Avoid using
default
exports, as they allow inconsistent naming during import.Empty blocks,
Where to break line → a higher syntactic level,
Horizontal alignment: discouraged.
Using markdown,
No line continuations,
Create a new array,
When adding new item to an array (given
const arr = [];
),Add an empty line before a comment. Comments should describe the purpose of the following code block.
Multi-line comments
But we use
/* */
in below case,Use camelCase for function names,
Use function declaration over function expression or arrow function,
Use arrow function in callback,
When using arrow functions, use implicit return when possible,
Prefer to use
for...of
and forEach
instead of classical for (;;)
Use
const
in for...of
and use let
in other loops.When you need to consider index,
Continue right after
if
, don’t use else
Use braces for control flows and loops,
Don’t add
break
after return
in switch
Use
default
as the last case, don’t use break
with it.Use brackets
{}
if you define a local variable inside each case.Use
try...catch
to catch error,👍 Only recoverable errors should be catch!
Use PascalCase to define a class name and camelCase for the object property, methods and instances.
Use lirerals, not constructors to create a new object,
Use method definition syntax,
Use shorthand,
Don’t mix quoted and unquoted keys,
Prefer to use conditional ternary operator,
Use strict equality operator,
Use shortcuts for boolean tests,
Use optional chaining
?.
Naming,
Use
let
or const
, not var
to declare a new variable!Declare one variable per line,
Void implicit type coercions,
To be continued…