JavaScript
Style
- Use
camelCasewith a leading lowercase for variables, methods, and object properties. - Use
CamelCasewith a leading uppercase for classes. - Use
SCREAMING_SNAKE_CASEfor constants.- Never use
const- it’s not supported in IE.
- Never use
- ALWAYS use semi-colons.
- ALWAYS use curly-braces when starting/ending blocks and functions. Start the curly brace on the same line as the block and end on a new line.
- Use whitespace to break code in logical paragraphs.
- Prefer single quotes
'for strings.
Functions
- Nested functions are okay; but
- DO NOT declare functions within blocks:
// bad
if (x) {
function foo() {};
}
// good
if (x) {
var foo = function() {};
}Other
- Avoid using
eval(). This can be very dangerous and can usually be avoided. - Do not use a
for..inloop UNLESS iterating over a hash. It’s best to use the standardforloop in most cases. - BE CONSISTENT.