Home

Awesome

Digitpaint JavaScript Style Guide() {

A mostly reasonable approach to JavaScript, taken from the excellent Airbnb JavaScript Style Guide

Note: this guide assumes you are using Babel, and requires that you use babel-preset-airbnb or the equivalent. It also assumes you are installing shims/polyfills in your app, with airbnb-browser-shims or the equivalent.

Downloads Downloads Gitter

This guide is available in other languages too. See Translation

Other Style Guides

Table of Contents

  1. Types
  2. References
  3. Objects
  4. Arrays
  5. Destructuring
  6. Strings
  7. Functions
  8. Arrow Functions
  9. Classes & Constructors
  10. Modules
  11. Iterators and Generators
  12. Properties
  13. Variables
  14. Hoisting
  15. Comparison Operators & Equality
  16. Blocks
  17. Control Statements
  18. Comments
  19. Whitespace
  20. Commas
  21. Semicolons
  22. Type Casting & Coercion
  23. Naming Conventions
  24. Accessors
  25. Events
  26. jQuery
  27. ECMAScript 5 Compatibility
  28. ECMAScript 6+ (ES 2015+) Styles
  29. Standard Library
  30. Testing
  31. Performance
  32. Resources
  33. In the Wild
  34. Translation
  35. The JavaScript Style Guide Guide
  36. Chat With Us About JavaScript
  37. Contributors
  38. License
  39. Amendments

Types

<a name="types--primitives"></a><a name="1.1"></a>

<a name="types--complex"></a><a name="1.2"></a>

⬆ back to top

References

<a name="references--prefer-const"></a><a name="2.1"></a>

<a name="references--disallow-var"></a><a name="2.2"></a>

<a name="references--block-scope"></a><a name="2.3"></a>

⬆ back to top

Objects

<a name="objects--no-new"></a><a name="3.1"></a>

<a name="es6-computed-properties"></a><a name="3.4"></a>

<a name="es6-object-shorthand"></a><a name="3.5"></a>

<a name="es6-object-concise"></a><a name="3.6"></a>

<a name="objects--grouped-shorthand"></a><a name="3.7"></a>

<a name="objects--quoted-props"></a><a name="3.8"></a>

<a name="objects--prototype-builtins"></a>

<a name="objects--rest-spread"></a>

⬆ back to top

Arrays

<a name="arrays--literals"></a><a name="4.1"></a>

<a name="arrays--push"></a><a name="4.2"></a>

<a name="es6-array-spreads"></a><a name="4.3"></a>

<a name="arrays--from"></a> <a name="arrays--from-iterable"></a><a name="4.4"></a>

<a name="arrays--from-array-like"></a>

<a name="arrays--mapping"></a>

<a name="arrays--callback-return"></a><a name="4.5"></a>

<a name="arrays--bracket-newline"></a>

⬆ back to top

Destructuring

<a name="destructuring--object"></a><a name="5.1"></a>

<a name="destructuring--array"></a><a name="5.2"></a>

<a name="destructuring--object-over-array"></a><a name="5.3"></a>

⬆ back to top

Strings

<a name="strings--quotes"></a><a name="6.1"></a>

<a name="strings--line-length"></a><a name="6.2"></a>

<a name="es6-template-literals"></a><a name="6.4"></a>

<a name="strings--eval"></a><a name="6.5"></a>

<a name="strings--escaping"></a>

⬆ back to top

Functions

<a name="functions--declarations"></a><a name="7.1"></a>

<a name="functions--iife"></a><a name="7.2"></a>

<a name="functions--in-blocks"></a><a name="7.3"></a>

<a name="functions--note-on-blocks"></a><a name="7.4"></a>

<a name="functions--arguments-shadow"></a><a name="7.5"></a>

<a name="es6-rest"></a><a name="7.6"></a>

<a name="es6-default-parameters"></a><a name="7.7"></a>

<a name="functions--default-side-effects"></a><a name="7.8"></a>

<a name="functions--defaults-last"></a><a name="7.9"></a>

<a name="functions--constructor"></a><a name="7.10"></a>

<a name="functions--signature-spacing"></a><a name="7.11"></a>

<a name="functions--mutate-params"></a><a name="7.12"></a>

<a name="functions--reassign-params"></a><a name="7.13"></a>

<a name="functions--spread-vs-apply"></a><a name="7.14"></a>

<a name="functions--signature-invocation-indentation"></a>

⬆ back to top

Arrow Functions

<a name="arrows--use-them"></a><a name="8.1"></a>

<a name="arrows--implicit-return"></a><a name="8.2"></a>

<a name="arrows--paren-wrap"></a><a name="8.3"></a>

<a name="arrows--one-arg-parens"></a><a name="8.4"></a>

<a name="arrows--confusing"></a><a name="8.5"></a>

<a name="whitespace--implicit-arrow-linebreak"></a>

⬆ back to top

Classes & Constructors

<a name="constructors--use-class"></a><a name="9.1"></a>

<a name="constructors--extends"></a><a name="9.2"></a>

<a name="constructors--chaining"></a><a name="9.3"></a>

<a name="constructors--tostring"></a><a name="9.4"></a>

<a name="constructors--no-useless"></a><a name="9.5"></a>

<a name="classes--no-duplicate-members"></a>

<a name="classes--methods-use-this"></a>

⬆ back to top

Modules

<a name="modules--use-them"></a><a name="10.1"></a>

<a name="modules--no-wildcard"></a><a name="10.2"></a>

<a name="modules--no-export-from-import"></a><a name="10.3"></a>

<a name="modules--no-duplicate-imports"></a>

<a name="modules--no-mutable-exports"></a>

<a name="modules--prefer-default-export"></a>

<a name="modules--imports-first"></a>

<a name="modules--multiline-imports-over-newlines"></a>

<a name="modules--no-webpack-loader-syntax"></a>

<a name="modules--import-extensions"></a>

⬆ back to top

Iterators and Generators

<a name="iterators--nope"></a><a name="11.1"></a>

<a name="generators--nope"></a><a name="11.2"></a>

<a name="generators--spacing"></a>

⬆ back to top

Properties

<a name="properties--dot"></a><a name="12.1"></a>

<a name="properties--bracket"></a><a name="12.2"></a>

<a name="es2016-properties--exponentiation-operator"></a>

⬆ back to top

Variables

<a name="variables--const"></a><a name="13.1"></a>

<a name="variables--one-const"></a><a name="13.2"></a>

<a name="variables--const-let-group"></a><a name="13.3"></a>

<a name="variables--define-where-used"></a><a name="13.4"></a>

<a name="variables--no-chain-assignment"></a><a name="13.5"></a>

<a name="variables--unary-increment-decrement"></a><a name="13.6"></a>

<a name="variables--linebreak"></a>

<a name="variables--no-unused-vars"></a>

⬆ back to top

Hoisting

<a name="hoisting--about"></a><a name="14.1"></a>

<a name="hoisting--anon-expressions"></a><a name="14.2"></a>

<a name="hoisting--named-expresions"></a><a name="hoisting--named-expressions"></a><a name="14.3"></a>

<a name="hoisting--declarations"></a><a name="14.4"></a>

⬆ back to top

Comparison Operators & Equality

<a name="comparison--eqeqeq"></a><a name="15.1"></a>

<a name="comparison--if"></a><a name="15.2"></a>

<a name="comparison--shortcuts"></a><a name="15.3"></a>

<a name="comparison--moreinfo"></a><a name="15.4"></a>

<a name="comparison--switch-blocks"></a><a name="15.5"></a>

<a name="comparison--nested-ternaries"></a><a name="15.6"></a>

<a name="comparison--unneeded-ternary"></a><a name="15.7"></a>

<a name="comparison--no-mixed-operators"></a>

⬆ back to top

Blocks

<a name="blocks--braces"></a><a name="16.1"></a>

<a name="blocks--cuddled-elses"></a><a name="16.2"></a>

<a name="blocks--no-else-return"></a><a name="16.3"></a>

⬆ back to top

Control Statements

<a name="control-statements"></a>

<a name="control-statement--value-selection"></a><a name="control-statements--value-selection"></a>

⬆ back to top

Comments

<a name="comments--multiline"></a><a name="17.1"></a>

<a name="comments--singleline"></a><a name="17.2"></a>

<a name="comments--spaces"></a>

<a name="comments--actionitems"></a><a name="17.3"></a>

<a name="comments--fixme"></a><a name="17.4"></a>

<a name="comments--todo"></a><a name="17.5"></a>

⬆ back to top

Whitespace

<a name="whitespace--spaces"></a><a name="18.1"></a>

<a name="whitespace--before-blocks"></a><a name="18.2"></a>

<a name="whitespace--around-keywords"></a><a name="18.3"></a>

<a name="whitespace--infix-ops"></a><a name="18.4"></a>

<a name="whitespace--newline-at-end"></a><a name="18.5"></a>

<a name="whitespace--chains"></a><a name="18.6"></a>

<a name="whitespace--after-blocks"></a><a name="18.7"></a>

<a name="whitespace--padded-blocks"></a><a name="18.8"></a>

<a name="whitespace--no-multiple-blanks"></a>

<a name="whitespace--in-parens"></a><a name="18.9"></a>

<a name="whitespace--in-brackets"></a><a name="18.10"></a>

<a name="whitespace--in-braces"></a><a name="18.11"></a>

<a name="whitespace--max-len"></a><a name="18.12"></a>

<a name="whitespace--block-spacing"></a>

<a name="whitespace--comma-spacing"></a>

<a name="whitespace--computed-property-spacing"></a>

<a name="whitespace--func-call-spacing"></a>

<a name="whitespace--key-spacing"></a>

<a name="whitespace--no-trailing-spaces"></a>

<a name="whitespace--no-multiple-empty-lines"></a>

⬆ back to top

Commas

<a name="commas--leading-trailing"></a><a name="19.1"></a>

<a name="commas--dangling"></a><a name="19.2"></a>

⬆ back to top

Semicolons

<a name="semicolons--required"></a><a name="20.1"></a>

⬆ back to top

Type Casting & Coercion

<a name="coercion--explicit"></a><a name="21.1"></a>

<a name="coercion--strings"></a><a name="21.2"></a>

<a name="coercion--numbers"></a><a name="21.3"></a>

<a name="coercion--comment-deviations"></a><a name="21.4"></a>

<a name="coercion--bitwise"></a><a name="21.5"></a>

<a name="coercion--booleans"></a><a name="21.6"></a>

⬆ back to top

Naming Conventions

<a name="naming--descriptive"></a><a name="22.1"></a>

<a name="naming--camelCase"></a><a name="22.2"></a>

<a name="naming--PascalCase"></a><a name="22.3"></a>

<a name="naming--leading-underscore"></a><a name="22.4"></a>

<a name="naming--self-this"></a><a name="22.5"></a>

<a name="naming--filename-matches-export"></a><a name="22.6"></a>

<a name="naming--camelCase-default-export"></a><a name="22.7"></a>

<a name="naming--PascalCase-singleton"></a><a name="22.8"></a>

<a name="naming--Acronyms-and-Initialisms"></a>

<a name="naming--uppercase"></a>

⬆ back to top

Accessors

<a name="accessors--not-required"></a><a name="23.1"></a>

<a name="accessors--no-getters-setters"></a><a name="23.2"></a>

<a name="accessors--boolean-prefix"></a><a name="23.3"></a>

<a name="accessors--consistent"></a><a name="23.4"></a>

⬆ back to top

Events

<a name="events--hash"></a><a name="24.1"></a>

⬆ back to top

jQuery

<a name="jquery--dollar-prefix"></a><a name="25.1"></a>

<a name="jquery--cache"></a><a name="25.2"></a>

<a name="jquery--queries"></a><a name="25.3"></a>

<a name="jquery--find"></a><a name="25.4"></a>

⬆ back to top

ECMAScript 5 Compatibility

<a name="es5-compat--kangax"></a><a name="26.1"></a>

⬆ back to top

<a name="ecmascript-6-styles"></a>

ECMAScript 6+ (ES 2015+) Styles

<a name="es6-styles"></a><a name="27.1"></a>

  1. Arrow Functions
  2. Classes
  3. Object Shorthand
  4. Object Concise
  5. Object Computed Properties
  6. Template Strings
  7. Destructuring
  8. Default Parameters
  9. Rest
  10. Array Spreads
  11. Let and Const
  12. Exponentiation Operator
  13. Iterators and Generators
  14. Modules

<a name="tc39-proposals"></a>

⬆ back to top

Standard Library

The Standard Library contains utilities that are functionally broken but remain for legacy reasons.

<a name="standard-library--isnan"></a>

<a name="standard-library--isfinite"></a>

⬆ back to top

Testing

<a name="testing--yup"></a><a name="28.1"></a>

<a name="testing--for-real"></a><a name="28.2"></a>

⬆ back to top

Performance

⬆ back to top

Resources

Learning ES6+

Read This

Tools

Other Style Guides

Other Styles

Further Reading

Books

Blogs

Podcasts

⬆ back to top

In the Wild

This is a list of organizations that are using this style guide. Send us a pull request and we'll add you to the list.

⬆ back to top

Translation

This style guide is also available in other languages:

The JavaScript Style Guide Guide

Chat With Us About JavaScript

Contributors

License

(The MIT License)

Copyright (c) 2012 Airbnb

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

⬆ back to top

Amendments

We encourage you to fork this guide and change the rules to fit your team’s style guide. Below, you may list some amendments to the style guide. This allows you to periodically update your style guide without having to deal with merge conflicts.

};