- Be consistent, but not religious about the style.
- Use tools to keep aligned with the guidelines.
- Strive for readable code and simple expressions.
- Eliminate all inconsistencies you spot.
- Strive for Functional Programming style.
- Space indentation for all files (2 spaces). See .editorconfig
- Smart tabs are ok.
- Use one space after
if
,for
,while
, etc. - Use one space after
function
for anonymous functions but not for named functions:
var fn = function () {}
function fn() {}
- Don't leave trailing whitespace at the end of lines.
- Use one
var
per variable unless you don't assign any values to it (and it's short enough):
var smth = 123
var next, prev, idx
- Use lowerCamelCase for variables and properties.
- User UPPERCASE for constants.
- Comment all non-obvious stuff.
- Use named functions. They make stack traces a lot easier to read.
- Avoid anonymous functions in chains.
- Use lowerCamelCase for function and method names.
- User UpperCamelCase for class names.
- 1TBS
- Single quotes for strings, unless you are writing JSON.
- Leading dot for chain calls.
use strict;
- Use
===
operator. - Write small functions (no more than 15 expressions).
- Avoid deeply nested expressions (max depth = 3).
- All projects must have pre-commit hooks for linting (use husky).
- Use .jshintrc and .editorconfig
Use FixMyJS