-
Notifications
You must be signed in to change notification settings - Fork 4
JavaScript Coding Style Guidelines
korenyushkin edited this page May 22, 2011
·
1 revision
This guide describes the style which should be used in all official Akshell JavaScript libraries.
- When adapting third-party code, stick with its style
- Line length should not exceed 80 characters
- Each var declaration should be on a separate line
- Always use semicolons
- Prefer ' over "
- Avoid complex nesting
- Always comment hacks, but try to avoid them
- Use == for primitive types
- Use === for objects
- Use Akshell goodies in all server code
- Use 2 spaces for indentation
- Tabs are forbidden
- Do not use space after a function name
- Do / Do not use a space after the function keyword if it's anonymous
- Do not pad parameter lists and functions calls with spaces, except after commas
- Do use space after if, for, while, function
- Do surround binary and ternary operators by spaces
- Do not surround unary operators by spaces
- Separate module-scope functions by 2 blank lines
- Do not place opening curly braces on a separate line (K&R over Allman)
- Do not use curly braces in if, else, for, while one-statement blocks
- Do use curly braces in if and else blocks if the other block has multiple statements
- Camel case variable and function names likeThis
- Camel case class and constructor names LikeThis
- Upper case constant names LIKE_THIS
- Names should be descriptive except traditional loop counters (i, j, k)
- Array variables should have names in plural form