Skip to content

Javascript

Zander Martineau edited this page Mar 27, 2018 · 8 revisions

Package management

Use npm, but use yarn if possible because of the speed and performance improvements.

Code style

Standard style is used for all code. Here are the most relevant rules:

  • 2 spaces - for indentation
  • Single quotes for strings – except to avoid escaping
  • No unused variables – this one catches tons of bugs!
  • No semicolons – It's fine. Really!
  • Never start a line with (, [, or `
    • This is the only gotcha with omitting semicolons – automatically checked for you!
    • More details
  • Space after keywords if (condition) { ... }
  • Space after function name function name (arg) { ... }
  • Always use === instead of == – but obj == null is allowed to check null || undefined.
  • Always handle the node.js err function parameter
  • Always prefix browser globals with window – except document and navigator are okay
  • Prevents accidental use of poorly-named browser globals like open, length, event, and name.

"Standard" plugins for your IDE can easily be found.

Additional Style guide

Follow AirBnB's comprehensive coding styleguide for best practices. We do not lint against this ruleset.

Resources

Clone this wiki locally