Home

Awesome

HowAboutWe JavaScript Style Guide

A mostly reasonable approach to JavaScript

<a name='TOC'>Table of Contents</a>

  1. Objects
  2. Arrays
  3. Strings
  4. Functions
  5. Properties
  6. Variables
  7. Conditional Expressions & Equality
  8. Blocks
  9. Comments
  10. Whitespace
  11. Leading Commas
  12. Semicolons
  13. Type Casting & Coercion
  14. Naming Conventions
  15. Accessors
  16. Constructors
  17. jQuery
  18. Modules
  19. ES5 Compatibility
  20. Performance
  21. Resources
  22. In the Wild
  23. Translation
  24. The JavaScript Style Guide Guide
  25. Contributors
  26. License

<a name='objects'>Objects</a>

<a name='arrays'>Arrays</a>

<a name='strings'>Strings</a>

<a name='functions'>Functions</a>

<a name='properties'>Properties</a>

<a name='variables'>Variables</a>

<a name='conditionals'>Conditional Expressions & Equality</a>

<a name='blocks'>Blocks</a>

<a name='comments'>Comments</a>

```javascript
// bad
function make(tag) {
  // ...stuff...
}

// good
/**
 * @param {String} tag
 * @return {Element} element
 */
function make(tag) {
  // ...stuff...
}

// best
/**
 * Returns a new element based on the passed in tag name.
 *
 * @param {String} tag
 *  Tag to create. -eg 'a', 'span', 'strong'
 * @return {Element} element
 *  DOM element object.
 */
function make(tag) {

  // ...stuff...

  return element;
}
```

**[[⬆]](#TOC)**

<a name='whitespace'>Whitespace</a>

<a name='leading-commas'>Leading Commas</a>

<a name='semicolons'>Semicolons</a>

<a name='type-coercion'>Type Casting & Coercion</a>

<a name='naming-conventions'>Naming Conventions</a>

<a name='accessors'>Accessors</a>

<a name='constructors'>Constructors</a>

<a name='jquery'>jQuery</a>

<a name='modules'>Modules</a>

<a name='es5'>ECMAScript 5 Compatibility</a>

[⬆]

<a name='performance'>Performance</a>

[⬆]

<a name='resources'>Resources</a>

Read This

Other Styleguides

Other Styles

Books

Blogs

Additional Articles

[⬆]

<a name='in-the-wild'>In the Wild</a>

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

<a name='translation'>Translation</a>

This style guide is also available in other languages:

<a name='guide-guide'>The JavaScript Style Guide Guide</a>

<a name='license'>License</a>

(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.

[⬆]