KISSmetrics Style Guides

 › JavaScript Style Guide

Initial version borrowed from AirBnb's. It can evolve as needed for our purposes.

Table of Contents

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

Types

Objects

Arrays

Strings

Functions

Properties

Variables

Hoisting

Conditional Expressions & Equality

Blocks

Comments

Documentation

Follow the YUI Docs

Whitespace

Commas

Edition 5 clarifies the fact that a trailing comma at the end of an ArrayInitialiser does not add to the length of the array. This is not a semantic change from Edition 3 but some implementations may have previously misinterpreted this.

```javascript
// bad
var hero = {
  firstName: 'Kevin',
  lastName: 'Flynn',
};

var heroes = [
  'Batman',
  'Superman',
];

// good
var hero = {
  firstName: 'Kevin',
  lastName: 'Flynn'
};

var heroes = [
  'Batman',
  'Superman'
];
```

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

Semicolons

Type Casting & Coercion

Naming Conventions

Accessors

Constructors

Events

[⬆]

Modules

jQuery

ECMAScript 5 Compatibility

[⬆]

Testing

Performance

[⬆]

Resources

Read This

Other Styleguides

Other Styles

Further Reading

Books

Blogs

[⬆]

In the Wild

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.

Translation

This style guide is also available in other languages:

The JavaScript Style Guide Guide

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.

[⬆]

};