diff --git a/index.html b/index.html index ebe5a6cb..7db2199f 100644 --- a/index.html +++ b/index.html @@ -30,8 +30,8 @@
Other Style Guides
diff --git a/params.json b/params.json index 6deb4eb8..56a69a64 100644 --- a/params.json +++ b/params.json @@ -1 +1 @@ -{"name":"Airbnb JavaScript Style Guide","tagline":"A mostly reasonable approach to JavaScript","body":"# Airbnb JavaScript Style Guide() {\r\n\r\n*A mostly reasonable approach to JavaScript*\r\n\r\n[](https://www.npmjs.com/package/eslint-config-airbnb)\r\n[](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)\r\n\r\nOther Style Guides\r\n - [ES5](es5/)\r\n - [React](react/)\r\n - [CSS & Sass](https://github.com/airbnb/css)\r\n - [Ruby](https://github.com/airbnb/ruby)\r\n\r\n## Table of Contents\r\n\r\n 1. [Types](#types)\r\n 1. [References](#references)\r\n 1. [Objects](#objects)\r\n 1. [Arrays](#arrays)\r\n 1. [Destructuring](#destructuring)\r\n 1. [Strings](#strings)\r\n 1. [Functions](#functions)\r\n 1. [Arrow Functions](#arrow-functions)\r\n 1. [Constructors](#constructors)\r\n 1. [Modules](#modules)\r\n 1. [Iterators and Generators](#iterators-and-generators)\r\n 1. [Properties](#properties)\r\n 1. [Variables](#variables)\r\n 1. [Hoisting](#hoisting)\r\n 1. [Comparison Operators & Equality](#comparison-operators--equality)\r\n 1. [Blocks](#blocks)\r\n 1. [Comments](#comments)\r\n 1. [Whitespace](#whitespace)\r\n 1. [Commas](#commas)\r\n 1. [Semicolons](#semicolons)\r\n 1. [Type Casting & Coercion](#type-casting--coercion)\r\n 1. [Naming Conventions](#naming-conventions)\r\n 1. [Accessors](#accessors)\r\n 1. [Events](#events)\r\n 1. [jQuery](#jquery)\r\n 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility)\r\n 1. [ECMAScript 6 Styles](#ecmascript-6-styles)\r\n 1. [Testing](#testing)\r\n 1. [Performance](#performance)\r\n 1. [Resources](#resources)\r\n 1. [In the Wild](#in-the-wild)\r\n 1. [Translation](#translation)\r\n 1. [The JavaScript Style Guide Guide](#the-javascript-style-guide-guide)\r\n 1. [Chat With Us About JavaScript](#chat-with-us-about-javascript)\r\n 1. [Contributors](#contributors)\r\n 1. [License](#license)\r\n\r\n## Types\r\n\r\n - [1.1](#1.1) **Primitives**: When you access a primitive type you work directly on its value.\r\n\r\n + `string`\r\n + `number`\r\n + `boolean`\r\n + `null`\r\n + `undefined`\r\n\r\n ```javascript\r\n const foo = 1;\r\n let bar = foo;\r\n\r\n bar = 9;\r\n\r\n console.log(foo, bar); // => 1, 9\r\n ```\r\n - [1.2](#1.2) **Complex**: When you access a complex type you work on a reference to its value.\r\n\r\n + `object`\r\n + `array`\r\n + `function`\r\n\r\n ```javascript\r\n const foo = [1, 2];\r\n const bar = foo;\r\n\r\n bar[0] = 9;\r\n\r\n console.log(foo[0], bar[0]); // => 9, 9\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## References\r\n\r\n - [2.1](#2.1) Use `const` for all of your references; avoid using `var`.\r\n\r\n > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.\r\n\r\n eslint rules: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html).\r\n\r\n ```javascript\r\n // bad\r\n var a = 1;\r\n var b = 2;\r\n\r\n // good\r\n const a = 1;\r\n const b = 2;\r\n ```\r\n\r\n - [2.2](#2.2) If you must reassign references, use `let` instead of `var`.\r\n\r\n > Why? `let` is block-scoped rather than function-scoped like `var`.\r\n\r\n eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html).\r\n\r\n ```javascript\r\n // bad\r\n var count = 1;\r\n if (true) {\r\n count += 1;\r\n }\r\n\r\n // good, use the let.\r\n let count = 1;\r\n if (true) {\r\n count += 1;\r\n }\r\n ```\r\n\r\n - [2.3](#2.3) Note that both `let` and `const` are block-scoped.\r\n\r\n ```javascript\r\n // const and let only exist in the blocks they are defined in.\r\n {\r\n let a = 1;\r\n const b = 1;\r\n }\r\n console.log(a); // ReferenceError\r\n console.log(b); // ReferenceError\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Objects\r\n\r\n - [3.1](#3.1) Use the literal syntax for object creation.\r\n\r\n eslint rules: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html).\r\n\r\n ```javascript\r\n // bad\r\n const item = new Object();\r\n\r\n // good\r\n const item = {};\r\n ```\r\n\r\n - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code.\r\n\r\n ```javascript\r\n // bad\r\n const superman = {\r\n default: { clark: 'kent' },\r\n private: true,\r\n };\r\n\r\n // good\r\n const superman = {\r\n defaults: { clark: 'kent' },\r\n hidden: true,\r\n };\r\n ```\r\n\r\n - [3.3](#3.3) Use readable synonyms in place of reserved words.\r\n\r\n ```javascript\r\n // bad\r\n const superman = {\r\n class: 'alien',\r\n };\r\n\r\n // bad\r\n const superman = {\r\n klass: 'alien',\r\n };\r\n\r\n // good\r\n const superman = {\r\n type: 'alien',\r\n };\r\n ```\r\n\r\n \r\n - [3.4](#3.4) Use computed property names when creating objects with dynamic property names.\r\n\r\n > Why? They allow you to define all the properties of an object in one place.\r\n\r\n ```javascript\r\n\r\n function getKey(k) {\r\n return `a key named ${k}`;\r\n }\r\n\r\n // bad\r\n const obj = {\r\n id: 5,\r\n name: 'San Francisco',\r\n };\r\n obj[getKey('enabled')] = true;\r\n\r\n // good\r\n const obj = {\r\n id: 5,\r\n name: 'San Francisco',\r\n [getKey('enabled')]: true,\r\n };\r\n ```\r\n\r\n \r\n - [3.5](#3.5) Use object method shorthand.\r\n\r\n eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html).\r\n\r\n ```javascript\r\n // bad\r\n const atom = {\r\n value: 1,\r\n\r\n addValue: function (value) {\r\n return atom.value + value;\r\n },\r\n };\r\n\r\n // good\r\n const atom = {\r\n value: 1,\r\n\r\n addValue(value) {\r\n return atom.value + value;\r\n },\r\n };\r\n ```\r\n\r\n \r\n - [3.6](#3.6) Use property value shorthand.\r\n\r\n > Why? It is shorter to write and descriptive.\r\n\r\n eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html).\r\n\r\n ```javascript\r\n const lukeSkywalker = 'Luke Skywalker';\r\n\r\n // bad\r\n const obj = {\r\n lukeSkywalker: lukeSkywalker,\r\n };\r\n\r\n // good\r\n const obj = {\r\n lukeSkywalker,\r\n };\r\n ```\r\n\r\n - [3.7](#3.7) Group your shorthand properties at the beginning of your object declaration.\r\n\r\n > Why? It's easier to tell which properties are using the shorthand.\r\n\r\n ```javascript\r\n const anakinSkywalker = 'Anakin Skywalker';\r\n const lukeSkywalker = 'Luke Skywalker';\r\n\r\n // bad\r\n const obj = {\r\n episodeOne: 1,\r\n twoJediWalkIntoACantina: 2,\r\n lukeSkywalker,\r\n episodeThree: 3,\r\n mayTheFourth: 4,\r\n anakinSkywalker,\r\n };\r\n\r\n // good\r\n const obj = {\r\n lukeSkywalker,\r\n anakinSkywalker,\r\n episodeOne: 1,\r\n twoJediWalkIntoACantina: 2,\r\n episodeThree: 3,\r\n mayTheFourth: 4,\r\n };\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Arrays\r\n\r\n - [4.1](#4.1) Use the literal syntax for array creation.\r\n\r\n eslint rules: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html).\r\n\r\n ```javascript\r\n // bad\r\n const items = new Array();\r\n\r\n // good\r\n const items = [];\r\n ```\r\n\r\n - [4.2](#4.2) Use Array#push instead of direct assignment to add items to an array.\r\n\r\n ```javascript\r\n const someStack = [];\r\n\r\n // bad\r\n someStack[someStack.length] = 'abracadabra';\r\n\r\n // good\r\n someStack.push('abracadabra');\r\n ```\r\n\r\n \r\n - [4.3](#4.3) Use array spreads `...` to copy arrays.\r\n\r\n ```javascript\r\n // bad\r\n const len = items.length;\r\n const itemsCopy = [];\r\n let i;\r\n\r\n for (i = 0; i < len; i++) {\r\n itemsCopy[i] = items[i];\r\n }\r\n\r\n // good\r\n const itemsCopy = [...items];\r\n ```\r\n - [4.4](#4.4) To convert an array-like object to an array, use Array#from.\r\n\r\n ```javascript\r\n const foo = document.querySelectorAll('.foo');\r\n const nodes = Array.from(foo);\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Destructuring\r\n\r\n - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object.\r\n\r\n > Why? Destructuring saves you from creating temporary references for those properties.\r\n\r\n ```javascript\r\n // bad\r\n function getFullName(user) {\r\n const firstName = user.firstName;\r\n const lastName = user.lastName;\r\n\r\n return `${firstName} ${lastName}`;\r\n }\r\n\r\n // good\r\n function getFullName(obj) {\r\n const { firstName, lastName } = obj;\r\n return `${firstName} ${lastName}`;\r\n }\r\n\r\n // best\r\n function getFullName({ firstName, lastName }) {\r\n return `${firstName} ${lastName}`;\r\n }\r\n ```\r\n\r\n - [5.2](#5.2) Use array destructuring.\r\n\r\n ```javascript\r\n const arr = [1, 2, 3, 4];\r\n\r\n // bad\r\n const first = arr[0];\r\n const second = arr[1];\r\n\r\n // good\r\n const [first, second] = arr;\r\n ```\r\n\r\n - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring.\r\n\r\n > Why? You can add new properties over time or change the order of things without breaking call sites.\r\n\r\n ```javascript\r\n // bad\r\n function processInput(input) {\r\n // then a miracle occurs\r\n return [left, right, top, bottom];\r\n }\r\n\r\n // the caller needs to think about the order of return data\r\n const [left, __, top] = processInput(input);\r\n\r\n // good\r\n function processInput(input) {\r\n // then a miracle occurs\r\n return { left, right, top, bottom };\r\n }\r\n\r\n // the caller selects only the data they need\r\n const { left, right } = processInput(input);\r\n ```\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Strings\r\n\r\n - [6.1](#6.1) Use single quotes `''` for strings.\r\n\r\n eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html).\r\n\r\n ```javascript\r\n // bad\r\n const name = \"Capt. Janeway\";\r\n\r\n // good\r\n const name = 'Capt. Janeway';\r\n ```\r\n\r\n - [6.2](#6.2) Strings longer than 100 characters should be written across multiple lines using string concatenation.\r\n - [6.3](#6.3) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40).\r\n\r\n ```javascript\r\n // bad\r\n const errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';\r\n\r\n // bad\r\n const errorMessage = 'This is a super long error that was thrown because \\\r\n of Batman. When you stop to think about how Batman had anything to do \\\r\n with this, you would get nowhere \\\r\n fast.';\r\n\r\n // good\r\n const errorMessage = 'This is a super long error that was thrown because ' +\r\n 'of Batman. When you stop to think about how Batman had anything to do ' +\r\n 'with this, you would get nowhere fast.';\r\n ```\r\n\r\n \r\n - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation.\r\n\r\n > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.\r\n\r\n eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html).\r\n\r\n ```javascript\r\n // bad\r\n function sayHi(name) {\r\n return 'How are you, ' + name + '?';\r\n }\r\n\r\n // bad\r\n function sayHi(name) {\r\n return ['How are you, ', name, '?'].join();\r\n }\r\n\r\n // good\r\n function sayHi(name) {\r\n return `How are you, ${name}?`;\r\n }\r\n ```\r\n - [6.5](#6.5) Never use `eval()` on a string, it opens too many vulnerabilities.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Functions\r\n\r\n - [7.1](#7.1) Use function declarations instead of function expressions.\r\n\r\n > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions.\r\n\r\n ```javascript\r\n // bad\r\n const foo = function () {\r\n };\r\n\r\n // good\r\n function foo() {\r\n }\r\n ```\r\n\r\n - [7.2](#7.2) Function expressions:\r\n\r\n ```javascript\r\n // immediately-invoked function expression (IIFE)\r\n (() => {\r\n console.log('Welcome to the Internet. Please follow me.');\r\n })();\r\n ```\r\n\r\n - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears.\r\n - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97).\r\n\r\n ```javascript\r\n // bad\r\n if (currentUser) {\r\n function test() {\r\n console.log('Nope.');\r\n }\r\n }\r\n\r\n // good\r\n let test;\r\n if (currentUser) {\r\n test = () => {\r\n console.log('Yup.');\r\n };\r\n }\r\n ```\r\n\r\n - [7.5](#7.5) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope.\r\n\r\n ```javascript\r\n // bad\r\n function nope(name, options, arguments) {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n function yup(name, options, args) {\r\n // ...stuff...\r\n }\r\n ```\r\n\r\n \r\n - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead.\r\n\r\n > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`.\r\n\r\n ```javascript\r\n // bad\r\n function concatenateAll() {\r\n const args = Array.prototype.slice.call(arguments);\r\n return args.join('');\r\n }\r\n\r\n // good\r\n function concatenateAll(...args) {\r\n return args.join('');\r\n }\r\n ```\r\n\r\n \r\n - [7.7](#7.7) Use default parameter syntax rather than mutating function arguments.\r\n\r\n ```javascript\r\n // really bad\r\n function handleThings(opts) {\r\n // No! We shouldn't mutate function arguments.\r\n // Double bad: if opts is falsy it'll be set to an object which may\r\n // be what you want but it can introduce subtle bugs.\r\n opts = opts || {};\r\n // ...\r\n }\r\n\r\n // still bad\r\n function handleThings(opts) {\r\n if (opts === void 0) {\r\n opts = {};\r\n }\r\n // ...\r\n }\r\n\r\n // good\r\n function handleThings(opts = {}) {\r\n // ...\r\n }\r\n ```\r\n\r\n - [7.8](#7.8) Avoid side effects with default parameters.\r\n\r\n > Why? They are confusing to reason about.\r\n\r\n ```javascript\r\n var b = 1;\r\n // bad\r\n function count(a = b++) {\r\n console.log(a);\r\n }\r\n count(); // 1\r\n count(); // 2\r\n count(3); // 3\r\n count(); // 3\r\n ```\r\n\r\n - [7.9](#7.9) Always put default parameters last.\r\n\r\n ```javascript\r\n // bad\r\n function handleThings(opts = {}, name) {\r\n // ...\r\n }\r\n\r\n // good\r\n function handleThings(name, opts = {}) {\r\n // ...\r\n }\r\n ```\r\n\r\n- [7.10](#7.10) Never use the Function constructor to create a new function.\r\n\r\n > Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.\r\n\r\n ```javascript\r\n // bad\r\n var add = new Function('a', 'b', 'return a + b');\r\n\r\n // still bad\r\n var subtract = Function('a', 'b', 'return a - b');\r\n ```\r\n\r\n- [7.11](#7.11) Spacing in a function signature.\r\n\r\n > Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name.\r\n\r\n ```javascript\r\n // bad\r\n const f = function(){};\r\n const g = function (){};\r\n const h = function() {};\r\n\r\n // good\r\n const x = function () {};\r\n const y = function a() {};\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Arrow Functions\r\n\r\n - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation.\r\n\r\n > Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax.\r\n\r\n > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.\r\n\r\n eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html).\r\n\r\n ```javascript\r\n // bad\r\n [1, 2, 3].map(function (x) {\r\n const y = x + 1;\r\n return x * y;\r\n });\r\n\r\n // good\r\n [1, 2, 3].map((x) => {\r\n const y = x + 1;\r\n return x * y;\r\n });\r\n ```\r\n\r\n - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement.\r\n\r\n > Why? Syntactic sugar. It reads well when multiple functions are chained together.\r\n\r\n > Why not? If you plan on returning an object.\r\n\r\n eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html).\r\n\r\n ```javascript\r\n // good\r\n [1, 2, 3].map(number => `A string containing the ${number}.`);\r\n\r\n // bad\r\n [1, 2, 3].map(number => {\r\n const nextNumber = number + 1;\r\n `A string containing the ${nextNumber}.`;\r\n });\r\n\r\n // good\r\n [1, 2, 3].map(number => {\r\n const nextNumber = number + 1;\r\n return `A string containing the ${nextNumber}.`;\r\n });\r\n ```\r\n\r\n - [8.3](#8.3) In case the expression spans over multiple lines, wrap it in parentheses for better readability.\r\n\r\n > Why? It shows clearly where the function starts and ends.\r\n\r\n ```js\r\n // bad\r\n [1, 2, 3].map(number => 'As time went by, the string containing the ' +\r\n `${number} became much longer. So we needed to break it over multiple ` +\r\n 'lines.'\r\n );\r\n\r\n // good\r\n [1, 2, 3].map(number => (\r\n `As time went by, the string containing the ${number} became much ` +\r\n 'longer. So we needed to break it over multiple lines.'\r\n ));\r\n ```\r\n\r\n\r\n - [8.4](#8.4) If your function only takes a single argument, feel free to omit the parentheses.\r\n\r\n > Why? Less visual clutter.\r\n\r\n eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html).\r\n\r\n ```js\r\n // good\r\n [1, 2, 3].map(x => x * x);\r\n\r\n // good\r\n [1, 2, 3].reduce((y, x) => x + y);\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Constructors\r\n\r\n - [9.1](#9.1) Always use `class`. Avoid manipulating `prototype` directly.\r\n\r\n > Why? `class` syntax is more concise and easier to reason about.\r\n\r\n ```javascript\r\n // bad\r\n function Queue(contents = []) {\r\n this._queue = [...contents];\r\n }\r\n Queue.prototype.pop = function () {\r\n const value = this._queue[0];\r\n this._queue.splice(0, 1);\r\n return value;\r\n }\r\n\r\n\r\n // good\r\n class Queue {\r\n constructor(contents = []) {\r\n this._queue = [...contents];\r\n }\r\n pop() {\r\n const value = this._queue[0];\r\n this._queue.splice(0, 1);\r\n return value;\r\n }\r\n }\r\n ```\r\n\r\n - [9.2](#9.2) Use `extends` for inheritance.\r\n\r\n > Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`.\r\n\r\n ```javascript\r\n // bad\r\n const inherits = require('inherits');\r\n function PeekableQueue(contents) {\r\n Queue.apply(this, contents);\r\n }\r\n inherits(PeekableQueue, Queue);\r\n PeekableQueue.prototype.peek = function () {\r\n return this._queue[0];\r\n }\r\n\r\n // good\r\n class PeekableQueue extends Queue {\r\n peek() {\r\n return this._queue[0];\r\n }\r\n }\r\n ```\r\n\r\n - [9.3](#9.3) Methods can return `this` to help with method chaining.\r\n\r\n ```javascript\r\n // bad\r\n Jedi.prototype.jump = function () {\r\n this.jumping = true;\r\n return true;\r\n };\r\n\r\n Jedi.prototype.setHeight = function (height) {\r\n this.height = height;\r\n };\r\n\r\n const luke = new Jedi();\r\n luke.jump(); // => true\r\n luke.setHeight(20); // => undefined\r\n\r\n // good\r\n class Jedi {\r\n jump() {\r\n this.jumping = true;\r\n return this;\r\n }\r\n\r\n setHeight(height) {\r\n this.height = height;\r\n return this;\r\n }\r\n }\r\n\r\n const luke = new Jedi();\r\n\r\n luke.jump()\r\n .setHeight(20);\r\n ```\r\n\r\n\r\n - [9.4](#9.4) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects.\r\n\r\n ```javascript\r\n class Jedi {\r\n constructor(options = {}) {\r\n this.name = options.name || 'no name';\r\n }\r\n\r\n getName() {\r\n return this.name;\r\n }\r\n\r\n toString() {\r\n return `Jedi - ${this.getName()}`;\r\n }\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Modules\r\n\r\n - [10.1](#10.1) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system.\r\n\r\n > Why? Modules are the future, let's start using the future now.\r\n\r\n ```javascript\r\n // bad\r\n const AirbnbStyleGuide = require('./AirbnbStyleGuide');\r\n module.exports = AirbnbStyleGuide.es6;\r\n\r\n // ok\r\n import AirbnbStyleGuide from './AirbnbStyleGuide';\r\n export default AirbnbStyleGuide.es6;\r\n\r\n // best\r\n import { es6 } from './AirbnbStyleGuide';\r\n export default es6;\r\n ```\r\n\r\n - [10.2](#10.2) Do not use wildcard imports.\r\n\r\n > Why? This makes sure you have a single default export.\r\n\r\n ```javascript\r\n // bad\r\n import * as AirbnbStyleGuide from './AirbnbStyleGuide';\r\n\r\n // good\r\n import AirbnbStyleGuide from './AirbnbStyleGuide';\r\n ```\r\n\r\n - [10.3](#10.3) And do not export directly from an import.\r\n\r\n > Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent.\r\n\r\n ```javascript\r\n // bad\r\n // filename es6.js\r\n export { es6 as default } from './airbnbStyleGuide';\r\n\r\n // good\r\n // filename es6.js\r\n import { es6 } from './AirbnbStyleGuide';\r\n export default es6;\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Iterators and Generators\r\n\r\n - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`.\r\n\r\n > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects.\r\n\r\n eslint rules: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html).\r\n\r\n ```javascript\r\n const numbers = [1, 2, 3, 4, 5];\r\n\r\n // bad\r\n let sum = 0;\r\n for (let num of numbers) {\r\n sum += num;\r\n }\r\n\r\n sum === 15;\r\n\r\n // good\r\n let sum = 0;\r\n numbers.forEach((num) => sum += num);\r\n sum === 15;\r\n\r\n // best (use the functional force)\r\n const sum = numbers.reduce((total, num) => total + num, 0);\r\n sum === 15;\r\n ```\r\n\r\n - [11.2](#11.2) Don't use generators for now.\r\n\r\n > Why? They don't transpile well to ES5.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Properties\r\n\r\n - [12.1](#12.1) Use dot notation when accessing properties.\r\n\r\n eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html).\r\n\r\n ```javascript\r\n const luke = {\r\n jedi: true,\r\n age: 28,\r\n };\r\n\r\n // bad\r\n const isJedi = luke['jedi'];\r\n\r\n // good\r\n const isJedi = luke.jedi;\r\n ```\r\n\r\n - [12.2](#12.2) Use subscript notation `[]` when accessing properties with a variable.\r\n\r\n ```javascript\r\n const luke = {\r\n jedi: true,\r\n age: 28,\r\n };\r\n\r\n function getProp(prop) {\r\n return luke[prop];\r\n }\r\n\r\n const isJedi = getProp('jedi');\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Variables\r\n\r\n - [13.1](#13.1) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that.\r\n\r\n ```javascript\r\n // bad\r\n superPower = new SuperPower();\r\n\r\n // good\r\n const superPower = new SuperPower();\r\n ```\r\n\r\n - [13.2](#13.2) Use one `const` declaration per variable.\r\n\r\n > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs.\r\n\r\n eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html).\r\n\r\n ```javascript\r\n // bad\r\n const items = getItems(),\r\n goSportsTeam = true,\r\n dragonball = 'z';\r\n\r\n // bad\r\n // (compare to above, and try to spot the mistake)\r\n const items = getItems(),\r\n goSportsTeam = true;\r\n dragonball = 'z';\r\n\r\n // good\r\n const items = getItems();\r\n const goSportsTeam = true;\r\n const dragonball = 'z';\r\n ```\r\n\r\n - [13.3](#13.3) Group all your `const`s and then group all your `let`s.\r\n\r\n > Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.\r\n\r\n ```javascript\r\n // bad\r\n let i, len, dragonball,\r\n items = getItems(),\r\n goSportsTeam = true;\r\n\r\n // bad\r\n let i;\r\n const items = getItems();\r\n let dragonball;\r\n const goSportsTeam = true;\r\n let len;\r\n\r\n // good\r\n const goSportsTeam = true;\r\n const items = getItems();\r\n let dragonball;\r\n let i;\r\n let length;\r\n ```\r\n\r\n - [13.4](#13.4) Assign variables where you need them, but place them in a reasonable place.\r\n\r\n > Why? `let` and `const` are block scoped and not function scoped.\r\n\r\n ```javascript\r\n // good\r\n function () {\r\n test();\r\n console.log('doing stuff..');\r\n\r\n //..other stuff..\r\n\r\n const name = getName();\r\n\r\n if (name === 'test') {\r\n return false;\r\n }\r\n\r\n return name;\r\n }\r\n\r\n // bad - unnecessary function call\r\n function (hasName) {\r\n const name = getName();\r\n\r\n if (!hasName) {\r\n return false;\r\n }\r\n\r\n this.setFirstName(name);\r\n\r\n return true;\r\n }\r\n\r\n // good\r\n function (hasName) {\r\n if (!hasName) {\r\n return false;\r\n }\r\n\r\n const name = getName();\r\n this.setFirstName(name);\r\n\r\n return true;\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Hoisting\r\n\r\n - [14.1](#14.1) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15).\r\n\r\n ```javascript\r\n // we know this wouldn't work (assuming there\r\n // is no notDefined global variable)\r\n function example() {\r\n console.log(notDefined); // => throws a ReferenceError\r\n }\r\n\r\n // creating a variable declaration after you\r\n // reference the variable will work due to\r\n // variable hoisting. Note: the assignment\r\n // value of `true` is not hoisted.\r\n function example() {\r\n console.log(declaredButNotAssigned); // => undefined\r\n var declaredButNotAssigned = true;\r\n }\r\n\r\n // The interpreter is hoisting the variable\r\n // declaration to the top of the scope,\r\n // which means our example could be rewritten as:\r\n function example() {\r\n let declaredButNotAssigned;\r\n console.log(declaredButNotAssigned); // => undefined\r\n declaredButNotAssigned = true;\r\n }\r\n\r\n // using const and let\r\n function example() {\r\n console.log(declaredButNotAssigned); // => throws a ReferenceError\r\n console.log(typeof declaredButNotAssigned); // => throws a ReferenceError\r\n const declaredButNotAssigned = true;\r\n }\r\n ```\r\n\r\n - [14.2](#14.2) Anonymous function expressions hoist their variable name, but not the function assignment.\r\n\r\n ```javascript\r\n function example() {\r\n console.log(anonymous); // => undefined\r\n\r\n anonymous(); // => TypeError anonymous is not a function\r\n\r\n var anonymous = function () {\r\n console.log('anonymous function expression');\r\n };\r\n }\r\n ```\r\n\r\n - [14.3](#14.3) Named function expressions hoist the variable name, not the function name or the function body.\r\n\r\n ```javascript\r\n function example() {\r\n console.log(named); // => undefined\r\n\r\n named(); // => TypeError named is not a function\r\n\r\n superPower(); // => ReferenceError superPower is not defined\r\n\r\n var named = function superPower() {\r\n console.log('Flying');\r\n };\r\n }\r\n\r\n // the same is true when the function name\r\n // is the same as the variable name.\r\n function example() {\r\n console.log(named); // => undefined\r\n\r\n named(); // => TypeError named is not a function\r\n\r\n var named = function named() {\r\n console.log('named');\r\n }\r\n }\r\n ```\r\n\r\n - [14.4](#14.4) Function declarations hoist their name and the function body.\r\n\r\n ```javascript\r\n function example() {\r\n superPower(); // => Flying\r\n\r\n function superPower() {\r\n console.log('Flying');\r\n }\r\n }\r\n ```\r\n\r\n - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Comparison Operators & Equality\r\n\r\n - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`.\r\n - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules:\r\n\r\n eslint rules: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html).\r\n\r\n + **Objects** evaluate to **true**\r\n + **Undefined** evaluates to **false**\r\n + **Null** evaluates to **false**\r\n + **Booleans** evaluate to **the value of the boolean**\r\n + **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**\r\n + **Strings** evaluate to **false** if an empty string `''`, otherwise **true**\r\n\r\n ```javascript\r\n if ([0]) {\r\n // true\r\n // An array is an object, objects evaluate to true\r\n }\r\n ```\r\n\r\n - [15.3](#15.3) Use shortcuts.\r\n\r\n ```javascript\r\n // bad\r\n if (name !== '') {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n if (name) {\r\n // ...stuff...\r\n }\r\n\r\n // bad\r\n if (collection.length > 0) {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n if (collection.length) {\r\n // ...stuff...\r\n }\r\n ```\r\n\r\n - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Blocks\r\n\r\n - [16.1](#16.1) Use braces with all multi-line blocks.\r\n\r\n ```javascript\r\n // bad\r\n if (test)\r\n return false;\r\n\r\n // good\r\n if (test) return false;\r\n\r\n // good\r\n if (test) {\r\n return false;\r\n }\r\n\r\n // bad\r\n function () { return false; }\r\n\r\n // good\r\n function () {\r\n return false;\r\n }\r\n ```\r\n\r\n - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your\r\n `if` block's closing brace.\r\n\r\n eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html).\r\n\r\n ```javascript\r\n // bad\r\n if (test) {\r\n thing1();\r\n thing2();\r\n }\r\n else {\r\n thing3();\r\n }\r\n\r\n // good\r\n if (test) {\r\n thing1();\r\n thing2();\r\n } else {\r\n thing3();\r\n }\r\n ```\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Comments\r\n\r\n - [17.1](#17.1) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values.\r\n\r\n ```javascript\r\n // bad\r\n // make() returns a new element\r\n // based on the passed in tag name\r\n //\r\n // @param {String} tag\r\n // @return {Element} element\r\n function make(tag) {\r\n\r\n // ...stuff...\r\n\r\n return element;\r\n }\r\n\r\n // good\r\n /**\r\n * make() returns a new element\r\n * based on the passed in tag name\r\n *\r\n * @param {String} tag\r\n * @return {Element} element\r\n */\r\n function make(tag) {\r\n\r\n // ...stuff...\r\n\r\n return element;\r\n }\r\n ```\r\n\r\n - [17.2](#17.2) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block.\r\n\r\n ```javascript\r\n // bad\r\n const active = true; // is current tab\r\n\r\n // good\r\n // is current tab\r\n const active = true;\r\n\r\n // bad\r\n function getType() {\r\n console.log('fetching type...');\r\n // set the default type to 'no type'\r\n const type = this._type || 'no type';\r\n\r\n return type;\r\n }\r\n\r\n // good\r\n function getType() {\r\n console.log('fetching type...');\r\n\r\n // set the default type to 'no type'\r\n const type = this._type || 'no type';\r\n\r\n return type;\r\n }\r\n\r\n // also good\r\n function getType() {\r\n // set the default type to 'no type'\r\n const type = this._type || 'no type';\r\n\r\n return type;\r\n }\r\n ```\r\n\r\n - [17.3](#17.3) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`.\r\n\r\n - [17.4](#17.4) Use `// FIXME:` to annotate problems.\r\n\r\n ```javascript\r\n class Calculator extends Abacus {\r\n constructor() {\r\n super();\r\n\r\n // FIXME: shouldn't use a global here\r\n total = 0;\r\n }\r\n }\r\n ```\r\n\r\n - [17.5](#17.5) Use `// TODO:` to annotate solutions to problems.\r\n\r\n ```javascript\r\n class Calculator extends Abacus {\r\n constructor() {\r\n super();\r\n\r\n // TODO: total should be configurable by an options param\r\n this.total = 0;\r\n }\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Whitespace\r\n\r\n - [18.1](#18.1) Use soft tabs set to 2 spaces.\r\n\r\n eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html).\r\n\r\n ```javascript\r\n // bad\r\n function () {\r\n ∙∙∙∙const name;\r\n }\r\n\r\n // bad\r\n function () {\r\n ∙const name;\r\n }\r\n\r\n // good\r\n function () {\r\n ∙∙const name;\r\n }\r\n ```\r\n\r\n - [18.2](#18.2) Place 1 space before the leading brace.\r\n\r\n eslint rules: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html).\r\n\r\n ```javascript\r\n // bad\r\n function test(){\r\n console.log('test');\r\n }\r\n\r\n // good\r\n function test() {\r\n console.log('test');\r\n }\r\n\r\n // bad\r\n dog.set('attr',{\r\n age: '1 year',\r\n breed: 'Bernese Mountain Dog',\r\n });\r\n\r\n // good\r\n dog.set('attr', {\r\n age: '1 year',\r\n breed: 'Bernese Mountain Dog',\r\n });\r\n ```\r\n\r\n - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations.\r\n\r\n eslint rules: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html).\r\n\r\n ```javascript\r\n // bad\r\n if(isJedi) {\r\n fight ();\r\n }\r\n\r\n // good\r\n if (isJedi) {\r\n fight();\r\n }\r\n\r\n // bad\r\n function fight () {\r\n console.log ('Swooosh!');\r\n }\r\n\r\n // good\r\n function fight() {\r\n console.log('Swooosh!');\r\n }\r\n ```\r\n\r\n - [18.4](#18.4) Set off operators with spaces.\r\n\r\n eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html).\r\n\r\n ```javascript\r\n // bad\r\n const x=y+5;\r\n\r\n // good\r\n const x = y + 5;\r\n ```\r\n\r\n - [18.5](#18.5) End files with a single newline character.\r\n\r\n ```javascript\r\n // bad\r\n (function (global) {\r\n // ...stuff...\r\n })(this);\r\n ```\r\n\r\n ```javascript\r\n // bad\r\n (function (global) {\r\n // ...stuff...\r\n })(this);↵\r\n ↵\r\n ```\r\n\r\n ```javascript\r\n // good\r\n (function (global) {\r\n // ...stuff...\r\n })(this);↵\r\n ```\r\n\r\n - [18.6](#18.6) Use indentation when making long method chains. Use a leading dot, which\r\n emphasizes that the line is a method call, not a new statement.\r\n\r\n ```javascript\r\n // bad\r\n $('#items').find('.selected').highlight().end().find('.open').updateCount();\r\n\r\n // bad\r\n $('#items').\r\n find('.selected').\r\n highlight().\r\n end().\r\n find('.open').\r\n updateCount();\r\n\r\n // good\r\n $('#items')\r\n .find('.selected')\r\n .highlight()\r\n .end()\r\n .find('.open')\r\n .updateCount();\r\n\r\n // bad\r\n const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true)\r\n .attr('width', (radius + margin) * 2).append('svg:g')\r\n .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')\r\n .call(tron.led);\r\n\r\n // good\r\n const leds = stage.selectAll('.led')\r\n .data(data)\r\n .enter().append('svg:svg')\r\n .classed('led', true)\r\n .attr('width', (radius + margin) * 2)\r\n .append('svg:g')\r\n .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')\r\n .call(tron.led);\r\n ```\r\n\r\n - [18.7](#18.7) Leave a blank line after blocks and before the next statement.\r\n\r\n ```javascript\r\n // bad\r\n if (foo) {\r\n return bar;\r\n }\r\n return baz;\r\n\r\n // good\r\n if (foo) {\r\n return bar;\r\n }\r\n\r\n return baz;\r\n\r\n // bad\r\n const obj = {\r\n foo() {\r\n },\r\n bar() {\r\n },\r\n };\r\n return obj;\r\n\r\n // good\r\n const obj = {\r\n foo() {\r\n },\r\n\r\n bar() {\r\n },\r\n };\r\n\r\n return obj;\r\n\r\n // bad\r\n const arr = [\r\n function foo() {\r\n },\r\n function bar() {\r\n },\r\n ];\r\n return arr;\r\n\r\n // good\r\n const arr = [\r\n function foo() {\r\n },\r\n\r\n function bar() {\r\n },\r\n ];\r\n\r\n return arr;\r\n ```\r\n\r\n - [18.8](#18.8) Do not pad your blocks with blank lines.\r\n\r\n eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html).\r\n\r\n ```javascript\r\n // bad\r\n function bar() {\r\n\r\n console.log(foo);\r\n\r\n }\r\n\r\n // also bad\r\n if (baz) {\r\n\r\n console.log(qux);\r\n } else {\r\n console.log(foo);\r\n\r\n }\r\n\r\n // good\r\n function bar() {\r\n console.log(foo);\r\n }\r\n\r\n // good\r\n if (baz) {\r\n console.log(qux);\r\n } else {\r\n console.log(foo);\r\n }\r\n ```\r\n\r\n - [18.9](#18.9) Do not add spaces inside parentheses.\r\n\r\n eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html).\r\n\r\n ```javascript\r\n // bad\r\n function bar( foo ) {\r\n return foo;\r\n }\r\n\r\n // good\r\n function bar(foo) {\r\n return foo;\r\n }\r\n\r\n // bad\r\n if ( foo ) {\r\n console.log(foo);\r\n }\r\n\r\n // good\r\n if (foo) {\r\n console.log(foo);\r\n }\r\n ```\r\n\r\n - [18.10](#18.10) Do not add spaces inside brackets.\r\n\r\n eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html).\r\n\r\n ```javascript\r\n // bad\r\n const foo = [ 1, 2, 3 ];\r\n console.log(foo[ 0 ]);\r\n\r\n // good\r\n const foo = [1, 2, 3];\r\n console.log(foo[0]);\r\n ```\r\n\r\n - [18.11](#18.11) Add spaces inside curly braces.\r\n\r\n eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html).\r\n\r\n ```javascript\r\n // bad\r\n const foo = {clark: 'kent'};\r\n\r\n // good\r\n const foo = { clark: 'kent' };\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Commas\r\n\r\n - [19.1](#19.1) Leading commas: **Nope.**\r\n\r\n eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html).\r\n\r\n ```javascript\r\n // bad\r\n const story = [\r\n once\r\n , upon\r\n , aTime\r\n ];\r\n\r\n // good\r\n const story = [\r\n once,\r\n upon,\r\n aTime,\r\n ];\r\n\r\n // bad\r\n const hero = {\r\n firstName: 'Ada'\r\n , lastName: 'Lovelace'\r\n , birthYear: 1815\r\n , superPower: 'computers'\r\n };\r\n\r\n // good\r\n const hero = {\r\n firstName: 'Ada',\r\n lastName: 'Lovelace',\r\n birthYear: 1815,\r\n superPower: 'computers',\r\n };\r\n ```\r\n\r\n - [19.2](#19.2) Additional trailing comma: **Yup.**\r\n\r\n eslint rules: [`no-comma-dangle`](http://eslint.org/docs/rules/no-comma-dangle.html).\r\n\r\n > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers.\r\n\r\n ```javascript\r\n // bad - git diff without trailing comma\r\n const hero = {\r\n firstName: 'Florence',\r\n - lastName: 'Nightingale'\r\n + lastName: 'Nightingale',\r\n + inventorOf: ['coxcomb graph', 'modern nursing']\r\n };\r\n\r\n // good - git diff with trailing comma\r\n const hero = {\r\n firstName: 'Florence',\r\n lastName: 'Nightingale',\r\n + inventorOf: ['coxcomb chart', 'modern nursing'],\r\n };\r\n\r\n // bad\r\n const hero = {\r\n firstName: 'Dana',\r\n lastName: 'Scully'\r\n };\r\n\r\n const heroes = [\r\n 'Batman',\r\n 'Superman'\r\n ];\r\n\r\n // good\r\n const hero = {\r\n firstName: 'Dana',\r\n lastName: 'Scully',\r\n };\r\n\r\n const heroes = [\r\n 'Batman',\r\n 'Superman',\r\n ];\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Semicolons\r\n\r\n - [20.1](#20.1) **Yup.**\r\n\r\n eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html).\r\n\r\n ```javascript\r\n // bad\r\n (function () {\r\n const name = 'Skywalker'\r\n return name\r\n })()\r\n\r\n // good\r\n (() => {\r\n const name = 'Skywalker';\r\n return name;\r\n })();\r\n\r\n // good (guards against the function becoming an argument when two files with IIFEs are concatenated)\r\n ;(() => {\r\n const name = 'Skywalker';\r\n return name;\r\n })();\r\n ```\r\n\r\n [Read more](http://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214%237365214).\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Type Casting & Coercion\r\n\r\n - [21.1](#21.1) Perform type coercion at the beginning of the statement.\r\n - [21.2](#21.2) Strings:\r\n\r\n ```javascript\r\n // => this.reviewScore = 9;\r\n\r\n // bad\r\n const totalScore = this.reviewScore + '';\r\n\r\n // good\r\n const totalScore = String(this.reviewScore);\r\n ```\r\n\r\n - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings.\r\n\r\n ```javascript\r\n const inputValue = '4';\r\n\r\n // bad\r\n const val = new Number(inputValue);\r\n\r\n // bad\r\n const val = +inputValue;\r\n\r\n // bad\r\n const val = inputValue >> 0;\r\n\r\n // bad\r\n const val = parseInt(inputValue);\r\n\r\n // good\r\n const val = Number(inputValue);\r\n\r\n // good\r\n const val = parseInt(inputValue, 10);\r\n ```\r\n\r\n - [21.4](#21.4) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing.\r\n\r\n ```javascript\r\n // good\r\n /**\r\n * parseInt was the reason my code was slow.\r\n * Bitshifting the String to coerce it to a\r\n * Number made it a lot faster.\r\n */\r\n const val = inputValue >> 0;\r\n ```\r\n\r\n - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647:\r\n\r\n ```javascript\r\n 2147483647 >> 0 //=> 2147483647\r\n 2147483648 >> 0 //=> -2147483648\r\n 2147483649 >> 0 //=> -2147483647\r\n ```\r\n\r\n - [21.6](#21.6) Booleans:\r\n\r\n ```javascript\r\n const age = 0;\r\n\r\n // bad\r\n const hasAge = new Boolean(age);\r\n\r\n // good\r\n const hasAge = Boolean(age);\r\n\r\n // good\r\n const hasAge = !!age;\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Naming Conventions\r\n\r\n - [22.1](#22.1) Avoid single letter names. Be descriptive with your naming.\r\n\r\n ```javascript\r\n // bad\r\n function q() {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n function query() {\r\n // ..stuff..\r\n }\r\n ```\r\n\r\n - [22.2](#22.2) Use camelCase when naming objects, functions, and instances.\r\n\r\n eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html).\r\n\r\n ```javascript\r\n // bad\r\n const OBJEcttsssss = {};\r\n const this_is_my_object = {};\r\n function c() {}\r\n\r\n // good\r\n const thisIsMyObject = {};\r\n function thisIsMyFunction() {}\r\n ```\r\n\r\n - [22.3](#22.3) Use PascalCase when naming constructors or classes.\r\n\r\n ```javascript\r\n // bad\r\n function user(options) {\r\n this.name = options.name;\r\n }\r\n\r\n const bad = new user({\r\n name: 'nope',\r\n });\r\n\r\n // good\r\n class User {\r\n constructor(options) {\r\n this.name = options.name;\r\n }\r\n }\r\n\r\n const good = new User({\r\n name: 'yup',\r\n });\r\n ```\r\n\r\n - [22.4](#22.4) Use a leading underscore `_` when naming private properties.\r\n\r\n eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html).\r\n\r\n ```javascript\r\n // bad\r\n this.__firstName__ = 'Panda';\r\n this.firstName_ = 'Panda';\r\n\r\n // good\r\n this._firstName = 'Panda';\r\n ```\r\n\r\n - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind.\r\n\r\n ```javascript\r\n // bad\r\n function foo() {\r\n const self = this;\r\n return function () {\r\n console.log(self);\r\n };\r\n }\r\n\r\n // bad\r\n function foo() {\r\n const that = this;\r\n return function () {\r\n console.log(that);\r\n };\r\n }\r\n\r\n // good\r\n function foo() {\r\n return () => {\r\n console.log(this);\r\n };\r\n }\r\n ```\r\n\r\n - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class.\r\n\r\n ```javascript\r\n // file contents\r\n class CheckBox {\r\n // ...\r\n }\r\n export default CheckBox;\r\n\r\n // in some other file\r\n // bad\r\n import CheckBox from './checkBox';\r\n\r\n // bad\r\n import CheckBox from './check_box';\r\n\r\n // good\r\n import CheckBox from './CheckBox';\r\n ```\r\n\r\n - [22.7](#22.7) Use camelCase when you export-default a function. Your filename should be identical to your function's name.\r\n\r\n ```javascript\r\n function makeStyleGuide() {\r\n }\r\n\r\n export default makeStyleGuide;\r\n ```\r\n\r\n - [22.8](#22.8) Use PascalCase when you export a singleton / function library / bare object.\r\n\r\n ```javascript\r\n const AirbnbStyleGuide = {\r\n es6: {\r\n }\r\n };\r\n\r\n export default AirbnbStyleGuide;\r\n ```\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Accessors\r\n\r\n - [23.1](#23.1) Accessor functions for properties are not required.\r\n - [23.2](#23.2) If you do make accessor functions use getVal() and setVal('hello').\r\n\r\n ```javascript\r\n // bad\r\n dragon.age();\r\n\r\n // good\r\n dragon.getAge();\r\n\r\n // bad\r\n dragon.age(25);\r\n\r\n // good\r\n dragon.setAge(25);\r\n ```\r\n\r\n - [23.3](#23.3) If the property is a `boolean`, use `isVal()` or `hasVal()`.\r\n\r\n ```javascript\r\n // bad\r\n if (!dragon.age()) {\r\n return false;\r\n }\r\n\r\n // good\r\n if (!dragon.hasAge()) {\r\n return false;\r\n }\r\n ```\r\n\r\n - [23.4](#23.4) It's okay to create get() and set() functions, but be consistent.\r\n\r\n ```javascript\r\n class Jedi {\r\n constructor(options = {}) {\r\n const lightsaber = options.lightsaber || 'blue';\r\n this.set('lightsaber', lightsaber);\r\n }\r\n\r\n set(key, val) {\r\n this[key] = val;\r\n }\r\n\r\n get(key) {\r\n return this[key];\r\n }\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Events\r\n\r\n - [24.1](#24.1) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:\r\n\r\n ```javascript\r\n // bad\r\n $(this).trigger('listingUpdated', listing.id);\r\n\r\n ...\r\n\r\n $(this).on('listingUpdated', function (e, listingId) {\r\n // do something with listingId\r\n });\r\n ```\r\n\r\n prefer:\r\n\r\n ```javascript\r\n // good\r\n $(this).trigger('listingUpdated', { listingId: listing.id });\r\n\r\n ...\r\n\r\n $(this).on('listingUpdated', function (e, data) {\r\n // do something with data.listingId\r\n });\r\n ```\r\n\r\n **[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## jQuery\r\n\r\n - [25.1](#25.1) Prefix jQuery object variables with a `$`.\r\n\r\n ```javascript\r\n // bad\r\n const sidebar = $('.sidebar');\r\n\r\n // good\r\n const $sidebar = $('.sidebar');\r\n\r\n // good\r\n const $sidebarBtn = $('.sidebar-btn');\r\n ```\r\n\r\n - [25.2](#25.2) Cache jQuery lookups.\r\n\r\n ```javascript\r\n // bad\r\n function setSidebar() {\r\n $('.sidebar').hide();\r\n\r\n // ...stuff...\r\n\r\n $('.sidebar').css({\r\n 'background-color': 'pink'\r\n });\r\n }\r\n\r\n // good\r\n function setSidebar() {\r\n const $sidebar = $('.sidebar');\r\n $sidebar.hide();\r\n\r\n // ...stuff...\r\n\r\n $sidebar.css({\r\n 'background-color': 'pink'\r\n });\r\n }\r\n ```\r\n\r\n - [25.3](#25.3) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)\r\n - [25.4](#25.4) Use `find` with scoped jQuery object queries.\r\n\r\n ```javascript\r\n // bad\r\n $('ul', '.sidebar').hide();\r\n\r\n // bad\r\n $('.sidebar').find('ul').hide();\r\n\r\n // good\r\n $('.sidebar ul').hide();\r\n\r\n // good\r\n $('.sidebar > ul').hide();\r\n\r\n // good\r\n $sidebar.find('ul').hide();\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## ECMAScript 5 Compatibility\r\n\r\n - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/).\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## ECMAScript 6 Styles\r\n\r\n - [27.1](#27.1) This is a collection of links to the various es6 features.\r\n\r\n1. [Arrow Functions](#arrow-functions)\r\n1. [Classes](#constructors)\r\n1. [Object Shorthand](#es6-object-shorthand)\r\n1. [Object Concise](#es6-object-concise)\r\n1. [Object Computed Properties](#es6-computed-properties)\r\n1. [Template Strings](#es6-template-literals)\r\n1. [Destructuring](#destructuring)\r\n1. [Default Parameters](#es6-default-parameters)\r\n1. [Rest](#es6-rest)\r\n1. [Array Spreads](#es6-array-spreads)\r\n1. [Let and Const](#references)\r\n1. [Iterators and Generators](#iterators-and-generators)\r\n1. [Modules](#modules)\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Testing\r\n\r\n - [28.1](#28.1) **Yup.**\r\n\r\n ```javascript\r\n function () {\r\n return true;\r\n }\r\n ```\r\n\r\n - [28.2](#28.2) **No, but seriously**:\r\n - Whichever testing framework you use, you should be writing tests!\r\n - Strive to write many small pure functions, and minimize where mutations occur.\r\n - Be cautious about stubs and mocks - they can make your tests more brittle.\r\n - We primarily use [`mocha`](https://www.npmjs.com/package/mocha) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules.\r\n - 100% test coverage is a good goal to strive for, even if it's not always practical to reach it.\r\n - Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Performance\r\n\r\n - [On Layout & Web Performance](http://www.kellegous.com/j/2013/01/26/layout-performance/)\r\n - [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)\r\n - [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)\r\n - [Bang Function](http://jsperf.com/bang-function)\r\n - [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13)\r\n - [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text)\r\n - [Long String Concatenation](http://jsperf.com/ya-string-concat)\r\n - Loading...\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Resources\r\n\r\n**Learning ES6**\r\n\r\n - [Draft ECMA 2015 (ES6) Spec](https://people.mozilla.org/~jorendorff/es6-draft.html)\r\n - [ExploringJS](http://exploringjs.com/)\r\n - [ES6 Compatibility Table](https://kangax.github.io/compat-table/es6/)\r\n - [Comprehensive Overview of ES6 Features](http://es6-features.org/)\r\n\r\n**Read This**\r\n\r\n - [Standard ECMA-262](http://www.ecma-international.org/ecma-262/6.0/index.html)\r\n\r\n**Tools**\r\n\r\n - Code Style Linters\r\n + [ESlint](http://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc)\r\n + [JSHint](http://jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc)\r\n + [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json)\r\n\r\n**Other Style Guides**\r\n\r\n - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)\r\n - [jQuery Core Style Guidelines](http://contribute.jquery.org/style-guide/js/)\r\n - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js)\r\n\r\n**Other Styles**\r\n\r\n - [Naming this in nested functions](https://gist.github.com/cjohansen/4135065) - Christian Johansen\r\n - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - Ross Allen\r\n - [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun\r\n - [Multiple var statements in JavaScript, not superfluous](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman\r\n\r\n**Further Reading**\r\n\r\n - [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll\r\n - [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer\r\n - [You Might Not Need jQuery](http://youmightnotneedjquery.com/) - Zack Bloom & Adam Schwartz\r\n - [ES6 Features](https://github.com/lukehoban/es6features) - Luke Hoban\r\n - [Frontend Guidelines](https://github.com/bendc/frontend-guidelines) - Benjamin De Cock\r\n\r\n**Books**\r\n\r\n - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford\r\n - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov\r\n - [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X) - Ross Harmes and Dustin Diaz\r\n - [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders\r\n - [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas\r\n - [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw\r\n - [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig\r\n - [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch\r\n - [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault\r\n - [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg\r\n - [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy\r\n - [JSBooks](http://jsbooks.revolunet.com/) - Julien Bouquillon\r\n - [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov\r\n - [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman\r\n - [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke\r\n - [You Don't Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson\r\n\r\n**Blogs**\r\n\r\n - [DailyJS](http://dailyjs.com/)\r\n - [JavaScript Weekly](http://javascriptweekly.com/)\r\n - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)\r\n - [Bocoup Weblog](https://bocoup.com/weblog)\r\n - [Adequately Good](http://www.adequatelygood.com/)\r\n - [NCZOnline](https://www.nczonline.net/)\r\n - [Perfection Kills](http://perfectionkills.com/)\r\n - [Ben Alman](http://benalman.com/)\r\n - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)\r\n - [Dustin Diaz](http://dustindiaz.com/)\r\n - [nettuts](http://code.tutsplus.com/?s=javascript)\r\n\r\n**Podcasts**\r\n\r\n - [JavaScript Jabber](https://devchat.tv/js-jabber/)\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## In the Wild\r\n\r\n 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.\r\n\r\n - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)\r\n - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript)\r\n - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)\r\n - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript)\r\n - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript)\r\n - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)\r\n - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/)\r\n - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript)\r\n - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide)\r\n - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)\r\n - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript)\r\n - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript)\r\n - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript)\r\n - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide)\r\n - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)\r\n - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md)\r\n - **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide)\r\n - **Gawker Media**: [gawkermedia/javascript](https://github.com/gawkermedia/javascript)\r\n - **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)\r\n - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)\r\n - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)\r\n - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide)\r\n - **Huballin**: [huballin/javascript](https://github.com/huballin/javascript)\r\n - **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript)\r\n - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md)\r\n - **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide)\r\n - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript)\r\n - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions)\r\n - **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md)\r\n - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)\r\n - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide)\r\n - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)\r\n - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)\r\n - **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript)\r\n - **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)\r\n - **Money Advice Service**: [moneyadviceservice/javascript](https://github.com/moneyadviceservice/javascript)\r\n - **Muber**: [muber/javascript](https://github.com/muber/javascript)\r\n - **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript)\r\n - **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript)\r\n - **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript)\r\n - **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript)\r\n - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript)\r\n - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)\r\n - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript)\r\n - **React**: [/facebook/react/blob/master/CONTRIBUTING.md#style-guide](https://github.com/facebook/react/blob/master/CONTRIBUTING.md#style-guide)\r\n - **REI**: [reidev/js-style-guide](https://github.com/reidev/js-style-guide)\r\n - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide)\r\n - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)\r\n - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)\r\n - **Springload**: [springload/javascript](https://github.com/springload/javascript)\r\n - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript)\r\n - **Target**: [target/javascript](https://github.com/target/javascript)\r\n - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript)\r\n - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript)\r\n - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide)\r\n - **Weggo**: [Weggo/javascript](https://github.com/Weggo/javascript)\r\n - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)\r\n - **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Translation\r\n\r\n This style guide is also available in other languages:\r\n\r\n -  **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)\r\n -  **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript)\r\n -  **Catalan**: [fpmweb/javascript-style-guide](https://github.com/fpmweb/javascript-style-guide)\r\n -  **Chinese (Simplified)**: [sivan/javascript-style-guide](https://github.com/sivan/javascript-style-guide)\r\n -  **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript)\r\n -  **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide)\r\n -  **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)\r\n -  **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide)\r\n -  **Japanese**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide)\r\n -  **Korean**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide)\r\n -  **Polish**: [mjurczyk/javascript](https://github.com/mjurczyk/javascript)\r\n -  **Russian**: [uprock/javascript](https://github.com/uprock/javascript)\r\n -  **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)\r\n -  **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide)\r\n\r\n## The JavaScript Style Guide Guide\r\n\r\n - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)\r\n\r\n## Chat With Us About JavaScript\r\n\r\n - Find us on [gitter](https://gitter.im/airbnb/javascript).\r\n\r\n## Contributors\r\n\r\n - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)\r\n\r\n\r\n## License\r\n\r\n(The MIT License)\r\n\r\nCopyright (c) 2014 Airbnb\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining\r\na copy of this software and associated documentation files (the\r\n'Software'), to deal in the Software without restriction, including\r\nwithout limitation the rights to use, copy, modify, merge, publish,\r\ndistribute, sublicense, and/or sell copies of the Software, and to\r\npermit persons to whom the Software is furnished to do so, subject to\r\nthe following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\r\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Amendments\r\n\r\nWe 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.\r\n\r\n# };\r\n","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file +{"name":"Airbnb JavaScript Style Guide","tagline":"A mostly reasonable approach to JavaScript","body":"# Airbnb JavaScript Style Guide() {\r\n\r\n*A mostly reasonable approach to JavaScript*\r\n\r\n[](https://www.npmjs.com/package/eslint-config-airbnb)\r\n[](https://gitter.im/airbnb/javascript?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)\r\n\r\nOther Style Guides\r\n - [ES5](https://github.com/airbnb/javascript/tree/master/es5)\r\n - [React](https://github.com/airbnb/javascript/tree/master/react)\r\n - [CSS & Sass](https://github.com/airbnb/css)\r\n - [Ruby](https://github.com/airbnb/ruby)\r\n\r\n## Table of Contents\r\n\r\n 1. [Types](#types)\r\n 1. [References](#references)\r\n 1. [Objects](#objects)\r\n 1. [Arrays](#arrays)\r\n 1. [Destructuring](#destructuring)\r\n 1. [Strings](#strings)\r\n 1. [Functions](#functions)\r\n 1. [Arrow Functions](#arrow-functions)\r\n 1. [Constructors](#constructors)\r\n 1. [Modules](#modules)\r\n 1. [Iterators and Generators](#iterators-and-generators)\r\n 1. [Properties](#properties)\r\n 1. [Variables](#variables)\r\n 1. [Hoisting](#hoisting)\r\n 1. [Comparison Operators & Equality](#comparison-operators--equality)\r\n 1. [Blocks](#blocks)\r\n 1. [Comments](#comments)\r\n 1. [Whitespace](#whitespace)\r\n 1. [Commas](#commas)\r\n 1. [Semicolons](#semicolons)\r\n 1. [Type Casting & Coercion](#type-casting--coercion)\r\n 1. [Naming Conventions](#naming-conventions)\r\n 1. [Accessors](#accessors)\r\n 1. [Events](#events)\r\n 1. [jQuery](#jquery)\r\n 1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility)\r\n 1. [ECMAScript 6 Styles](#ecmascript-6-styles)\r\n 1. [Testing](#testing)\r\n 1. [Performance](#performance)\r\n 1. [Resources](#resources)\r\n 1. [In the Wild](#in-the-wild)\r\n 1. [Translation](#translation)\r\n 1. [The JavaScript Style Guide Guide](#the-javascript-style-guide-guide)\r\n 1. [Chat With Us About JavaScript](#chat-with-us-about-javascript)\r\n 1. [Contributors](#contributors)\r\n 1. [License](#license)\r\n\r\n## Types\r\n\r\n - [1.1](#1.1) **Primitives**: When you access a primitive type you work directly on its value.\r\n\r\n + `string`\r\n + `number`\r\n + `boolean`\r\n + `null`\r\n + `undefined`\r\n\r\n ```javascript\r\n const foo = 1;\r\n let bar = foo;\r\n\r\n bar = 9;\r\n\r\n console.log(foo, bar); // => 1, 9\r\n ```\r\n - [1.2](#1.2) **Complex**: When you access a complex type you work on a reference to its value.\r\n\r\n + `object`\r\n + `array`\r\n + `function`\r\n\r\n ```javascript\r\n const foo = [1, 2];\r\n const bar = foo;\r\n\r\n bar[0] = 9;\r\n\r\n console.log(foo[0], bar[0]); // => 9, 9\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## References\r\n\r\n - [2.1](#2.1) Use `const` for all of your references; avoid using `var`.\r\n\r\n > Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code.\r\n\r\n eslint rules: [`prefer-const`](http://eslint.org/docs/rules/prefer-const.html), [`no-const-assign`](http://eslint.org/docs/rules/no-const-assign.html).\r\n\r\n ```javascript\r\n // bad\r\n var a = 1;\r\n var b = 2;\r\n\r\n // good\r\n const a = 1;\r\n const b = 2;\r\n ```\r\n\r\n - [2.2](#2.2) If you must reassign references, use `let` instead of `var`.\r\n\r\n > Why? `let` is block-scoped rather than function-scoped like `var`.\r\n\r\n eslint rules: [`no-var`](http://eslint.org/docs/rules/no-var.html).\r\n\r\n ```javascript\r\n // bad\r\n var count = 1;\r\n if (true) {\r\n count += 1;\r\n }\r\n\r\n // good, use the let.\r\n let count = 1;\r\n if (true) {\r\n count += 1;\r\n }\r\n ```\r\n\r\n - [2.3](#2.3) Note that both `let` and `const` are block-scoped.\r\n\r\n ```javascript\r\n // const and let only exist in the blocks they are defined in.\r\n {\r\n let a = 1;\r\n const b = 1;\r\n }\r\n console.log(a); // ReferenceError\r\n console.log(b); // ReferenceError\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Objects\r\n\r\n - [3.1](#3.1) Use the literal syntax for object creation.\r\n\r\n eslint rules: [`no-new-object`](http://eslint.org/docs/rules/no-new-object.html).\r\n\r\n ```javascript\r\n // bad\r\n const item = new Object();\r\n\r\n // good\r\n const item = {};\r\n ```\r\n\r\n - [3.2](#3.2) If your code will be executed in browsers in script context, don't use [reserved words](http://es5.github.io/#x7.6.1) as keys. It won't work in IE8. [More info](https://github.com/airbnb/javascript/issues/61). It’s OK to use them in ES6 modules and server-side code.\r\n\r\n ```javascript\r\n // bad\r\n const superman = {\r\n default: { clark: 'kent' },\r\n private: true,\r\n };\r\n\r\n // good\r\n const superman = {\r\n defaults: { clark: 'kent' },\r\n hidden: true,\r\n };\r\n ```\r\n\r\n - [3.3](#3.3) Use readable synonyms in place of reserved words.\r\n\r\n ```javascript\r\n // bad\r\n const superman = {\r\n class: 'alien',\r\n };\r\n\r\n // bad\r\n const superman = {\r\n klass: 'alien',\r\n };\r\n\r\n // good\r\n const superman = {\r\n type: 'alien',\r\n };\r\n ```\r\n\r\n \r\n - [3.4](#3.4) Use computed property names when creating objects with dynamic property names.\r\n\r\n > Why? They allow you to define all the properties of an object in one place.\r\n\r\n ```javascript\r\n\r\n function getKey(k) {\r\n return `a key named ${k}`;\r\n }\r\n\r\n // bad\r\n const obj = {\r\n id: 5,\r\n name: 'San Francisco',\r\n };\r\n obj[getKey('enabled')] = true;\r\n\r\n // good\r\n const obj = {\r\n id: 5,\r\n name: 'San Francisco',\r\n [getKey('enabled')]: true,\r\n };\r\n ```\r\n\r\n \r\n - [3.5](#3.5) Use object method shorthand.\r\n\r\n eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html).\r\n\r\n ```javascript\r\n // bad\r\n const atom = {\r\n value: 1,\r\n\r\n addValue: function (value) {\r\n return atom.value + value;\r\n },\r\n };\r\n\r\n // good\r\n const atom = {\r\n value: 1,\r\n\r\n addValue(value) {\r\n return atom.value + value;\r\n },\r\n };\r\n ```\r\n\r\n \r\n - [3.6](#3.6) Use property value shorthand.\r\n\r\n > Why? It is shorter to write and descriptive.\r\n\r\n eslint rules: [`object-shorthand`](http://eslint.org/docs/rules/object-shorthand.html).\r\n\r\n ```javascript\r\n const lukeSkywalker = 'Luke Skywalker';\r\n\r\n // bad\r\n const obj = {\r\n lukeSkywalker: lukeSkywalker,\r\n };\r\n\r\n // good\r\n const obj = {\r\n lukeSkywalker,\r\n };\r\n ```\r\n\r\n - [3.7](#3.7) Group your shorthand properties at the beginning of your object declaration.\r\n\r\n > Why? It's easier to tell which properties are using the shorthand.\r\n\r\n ```javascript\r\n const anakinSkywalker = 'Anakin Skywalker';\r\n const lukeSkywalker = 'Luke Skywalker';\r\n\r\n // bad\r\n const obj = {\r\n episodeOne: 1,\r\n twoJediWalkIntoACantina: 2,\r\n lukeSkywalker,\r\n episodeThree: 3,\r\n mayTheFourth: 4,\r\n anakinSkywalker,\r\n };\r\n\r\n // good\r\n const obj = {\r\n lukeSkywalker,\r\n anakinSkywalker,\r\n episodeOne: 1,\r\n twoJediWalkIntoACantina: 2,\r\n episodeThree: 3,\r\n mayTheFourth: 4,\r\n };\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Arrays\r\n\r\n - [4.1](#4.1) Use the literal syntax for array creation.\r\n\r\n eslint rules: [`no-array-constructor`](http://eslint.org/docs/rules/no-array-constructor.html).\r\n\r\n ```javascript\r\n // bad\r\n const items = new Array();\r\n\r\n // good\r\n const items = [];\r\n ```\r\n\r\n - [4.2](#4.2) Use Array#push instead of direct assignment to add items to an array.\r\n\r\n ```javascript\r\n const someStack = [];\r\n\r\n // bad\r\n someStack[someStack.length] = 'abracadabra';\r\n\r\n // good\r\n someStack.push('abracadabra');\r\n ```\r\n\r\n \r\n - [4.3](#4.3) Use array spreads `...` to copy arrays.\r\n\r\n ```javascript\r\n // bad\r\n const len = items.length;\r\n const itemsCopy = [];\r\n let i;\r\n\r\n for (i = 0; i < len; i++) {\r\n itemsCopy[i] = items[i];\r\n }\r\n\r\n // good\r\n const itemsCopy = [...items];\r\n ```\r\n - [4.4](#4.4) To convert an array-like object to an array, use Array#from.\r\n\r\n ```javascript\r\n const foo = document.querySelectorAll('.foo');\r\n const nodes = Array.from(foo);\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Destructuring\r\n\r\n - [5.1](#5.1) Use object destructuring when accessing and using multiple properties of an object.\r\n\r\n > Why? Destructuring saves you from creating temporary references for those properties.\r\n\r\n ```javascript\r\n // bad\r\n function getFullName(user) {\r\n const firstName = user.firstName;\r\n const lastName = user.lastName;\r\n\r\n return `${firstName} ${lastName}`;\r\n }\r\n\r\n // good\r\n function getFullName(obj) {\r\n const { firstName, lastName } = obj;\r\n return `${firstName} ${lastName}`;\r\n }\r\n\r\n // best\r\n function getFullName({ firstName, lastName }) {\r\n return `${firstName} ${lastName}`;\r\n }\r\n ```\r\n\r\n - [5.2](#5.2) Use array destructuring.\r\n\r\n ```javascript\r\n const arr = [1, 2, 3, 4];\r\n\r\n // bad\r\n const first = arr[0];\r\n const second = arr[1];\r\n\r\n // good\r\n const [first, second] = arr;\r\n ```\r\n\r\n - [5.3](#5.3) Use object destructuring for multiple return values, not array destructuring.\r\n\r\n > Why? You can add new properties over time or change the order of things without breaking call sites.\r\n\r\n ```javascript\r\n // bad\r\n function processInput(input) {\r\n // then a miracle occurs\r\n return [left, right, top, bottom];\r\n }\r\n\r\n // the caller needs to think about the order of return data\r\n const [left, __, top] = processInput(input);\r\n\r\n // good\r\n function processInput(input) {\r\n // then a miracle occurs\r\n return { left, right, top, bottom };\r\n }\r\n\r\n // the caller selects only the data they need\r\n const { left, right } = processInput(input);\r\n ```\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Strings\r\n\r\n - [6.1](#6.1) Use single quotes `''` for strings.\r\n\r\n eslint rules: [`quotes`](http://eslint.org/docs/rules/quotes.html).\r\n\r\n ```javascript\r\n // bad\r\n const name = \"Capt. Janeway\";\r\n\r\n // good\r\n const name = 'Capt. Janeway';\r\n ```\r\n\r\n - [6.2](#6.2) Strings longer than 100 characters should be written across multiple lines using string concatenation.\r\n - [6.3](#6.3) Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) & [Discussion](https://github.com/airbnb/javascript/issues/40).\r\n\r\n ```javascript\r\n // bad\r\n const errorMessage = 'This is a super long error that was thrown because of Batman. When you stop to think about how Batman had anything to do with this, you would get nowhere fast.';\r\n\r\n // bad\r\n const errorMessage = 'This is a super long error that was thrown because \\\r\n of Batman. When you stop to think about how Batman had anything to do \\\r\n with this, you would get nowhere \\\r\n fast.';\r\n\r\n // good\r\n const errorMessage = 'This is a super long error that was thrown because ' +\r\n 'of Batman. When you stop to think about how Batman had anything to do ' +\r\n 'with this, you would get nowhere fast.';\r\n ```\r\n\r\n \r\n - [6.4](#6.4) When programmatically building up strings, use template strings instead of concatenation.\r\n\r\n > Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.\r\n\r\n eslint rules: [`prefer-template`](http://eslint.org/docs/rules/prefer-template.html).\r\n\r\n ```javascript\r\n // bad\r\n function sayHi(name) {\r\n return 'How are you, ' + name + '?';\r\n }\r\n\r\n // bad\r\n function sayHi(name) {\r\n return ['How are you, ', name, '?'].join();\r\n }\r\n\r\n // good\r\n function sayHi(name) {\r\n return `How are you, ${name}?`;\r\n }\r\n ```\r\n - [6.5](#6.5) Never use `eval()` on a string, it opens too many vulnerabilities.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Functions\r\n\r\n - [7.1](#7.1) Use function declarations instead of function expressions.\r\n\r\n > Why? Function declarations are named, so they're easier to identify in call stacks. Also, the whole body of a function declaration is hoisted, whereas only the reference of a function expression is hoisted. This rule makes it possible to always use [Arrow Functions](#arrow-functions) in place of function expressions.\r\n\r\n ```javascript\r\n // bad\r\n const foo = function () {\r\n };\r\n\r\n // good\r\n function foo() {\r\n }\r\n ```\r\n\r\n - [7.2](#7.2) Function expressions:\r\n\r\n ```javascript\r\n // immediately-invoked function expression (IIFE)\r\n (() => {\r\n console.log('Welcome to the Internet. Please follow me.');\r\n })();\r\n ```\r\n\r\n - [7.3](#7.3) Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead. Browsers will allow you to do it, but they all interpret it differently, which is bad news bears.\r\n - [7.4](#7.4) **Note:** ECMA-262 defines a `block` as a list of statements. A function declaration is not a statement. [Read ECMA-262's note on this issue](http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf#page=97).\r\n\r\n ```javascript\r\n // bad\r\n if (currentUser) {\r\n function test() {\r\n console.log('Nope.');\r\n }\r\n }\r\n\r\n // good\r\n let test;\r\n if (currentUser) {\r\n test = () => {\r\n console.log('Yup.');\r\n };\r\n }\r\n ```\r\n\r\n - [7.5](#7.5) Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope.\r\n\r\n ```javascript\r\n // bad\r\n function nope(name, options, arguments) {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n function yup(name, options, args) {\r\n // ...stuff...\r\n }\r\n ```\r\n\r\n \r\n - [7.6](#7.6) Never use `arguments`, opt to use rest syntax `...` instead.\r\n\r\n > Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`.\r\n\r\n ```javascript\r\n // bad\r\n function concatenateAll() {\r\n const args = Array.prototype.slice.call(arguments);\r\n return args.join('');\r\n }\r\n\r\n // good\r\n function concatenateAll(...args) {\r\n return args.join('');\r\n }\r\n ```\r\n\r\n \r\n - [7.7](#7.7) Use default parameter syntax rather than mutating function arguments.\r\n\r\n ```javascript\r\n // really bad\r\n function handleThings(opts) {\r\n // No! We shouldn't mutate function arguments.\r\n // Double bad: if opts is falsy it'll be set to an object which may\r\n // be what you want but it can introduce subtle bugs.\r\n opts = opts || {};\r\n // ...\r\n }\r\n\r\n // still bad\r\n function handleThings(opts) {\r\n if (opts === void 0) {\r\n opts = {};\r\n }\r\n // ...\r\n }\r\n\r\n // good\r\n function handleThings(opts = {}) {\r\n // ...\r\n }\r\n ```\r\n\r\n - [7.8](#7.8) Avoid side effects with default parameters.\r\n\r\n > Why? They are confusing to reason about.\r\n\r\n ```javascript\r\n var b = 1;\r\n // bad\r\n function count(a = b++) {\r\n console.log(a);\r\n }\r\n count(); // 1\r\n count(); // 2\r\n count(3); // 3\r\n count(); // 3\r\n ```\r\n\r\n - [7.9](#7.9) Always put default parameters last.\r\n\r\n ```javascript\r\n // bad\r\n function handleThings(opts = {}, name) {\r\n // ...\r\n }\r\n\r\n // good\r\n function handleThings(name, opts = {}) {\r\n // ...\r\n }\r\n ```\r\n\r\n- [7.10](#7.10) Never use the Function constructor to create a new function.\r\n\r\n > Why? Creating a function in this way evaluates a string similarly to eval(), which opens vulnerabilities.\r\n\r\n ```javascript\r\n // bad\r\n var add = new Function('a', 'b', 'return a + b');\r\n\r\n // still bad\r\n var subtract = Function('a', 'b', 'return a - b');\r\n ```\r\n\r\n- [7.11](#7.11) Spacing in a function signature.\r\n\r\n > Why? Consistency is good, and you shouldn’t have to add or remove a space when adding or removing a name.\r\n\r\n ```javascript\r\n // bad\r\n const f = function(){};\r\n const g = function (){};\r\n const h = function() {};\r\n\r\n // good\r\n const x = function () {};\r\n const y = function a() {};\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Arrow Functions\r\n\r\n - [8.1](#8.1) When you must use function expressions (as when passing an anonymous function), use arrow function notation.\r\n\r\n > Why? It creates a version of the function that executes in the context of `this`, which is usually what you want, and is a more concise syntax.\r\n\r\n > Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.\r\n\r\n eslint rules: [`prefer-arrow-callback`](http://eslint.org/docs/rules/prefer-arrow-callback.html), [`arrow-spacing`](http://eslint.org/docs/rules/arrow-spacing.html).\r\n\r\n ```javascript\r\n // bad\r\n [1, 2, 3].map(function (x) {\r\n const y = x + 1;\r\n return x * y;\r\n });\r\n\r\n // good\r\n [1, 2, 3].map((x) => {\r\n const y = x + 1;\r\n return x * y;\r\n });\r\n ```\r\n\r\n - [8.2](#8.2) If the function body consists of a single expression, feel free to omit the braces and use the implicit return. Otherwise use a `return` statement.\r\n\r\n > Why? Syntactic sugar. It reads well when multiple functions are chained together.\r\n\r\n > Why not? If you plan on returning an object.\r\n\r\n eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html), [`arrow-body-style`](http://eslint.org/docs/rules/arrow-body-style.html).\r\n\r\n ```javascript\r\n // good\r\n [1, 2, 3].map(number => `A string containing the ${number}.`);\r\n\r\n // bad\r\n [1, 2, 3].map(number => {\r\n const nextNumber = number + 1;\r\n `A string containing the ${nextNumber}.`;\r\n });\r\n\r\n // good\r\n [1, 2, 3].map(number => {\r\n const nextNumber = number + 1;\r\n return `A string containing the ${nextNumber}.`;\r\n });\r\n ```\r\n\r\n - [8.3](#8.3) In case the expression spans over multiple lines, wrap it in parentheses for better readability.\r\n\r\n > Why? It shows clearly where the function starts and ends.\r\n\r\n ```js\r\n // bad\r\n [1, 2, 3].map(number => 'As time went by, the string containing the ' +\r\n `${number} became much longer. So we needed to break it over multiple ` +\r\n 'lines.'\r\n );\r\n\r\n // good\r\n [1, 2, 3].map(number => (\r\n `As time went by, the string containing the ${number} became much ` +\r\n 'longer. So we needed to break it over multiple lines.'\r\n ));\r\n ```\r\n\r\n\r\n - [8.4](#8.4) If your function only takes a single argument, feel free to omit the parentheses.\r\n\r\n > Why? Less visual clutter.\r\n\r\n eslint rules: [`arrow-parens`](http://eslint.org/docs/rules/arrow-parens.html).\r\n\r\n ```js\r\n // good\r\n [1, 2, 3].map(x => x * x);\r\n\r\n // good\r\n [1, 2, 3].reduce((y, x) => x + y);\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Constructors\r\n\r\n - [9.1](#9.1) Always use `class`. Avoid manipulating `prototype` directly.\r\n\r\n > Why? `class` syntax is more concise and easier to reason about.\r\n\r\n ```javascript\r\n // bad\r\n function Queue(contents = []) {\r\n this._queue = [...contents];\r\n }\r\n Queue.prototype.pop = function () {\r\n const value = this._queue[0];\r\n this._queue.splice(0, 1);\r\n return value;\r\n }\r\n\r\n\r\n // good\r\n class Queue {\r\n constructor(contents = []) {\r\n this._queue = [...contents];\r\n }\r\n pop() {\r\n const value = this._queue[0];\r\n this._queue.splice(0, 1);\r\n return value;\r\n }\r\n }\r\n ```\r\n\r\n - [9.2](#9.2) Use `extends` for inheritance.\r\n\r\n > Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`.\r\n\r\n ```javascript\r\n // bad\r\n const inherits = require('inherits');\r\n function PeekableQueue(contents) {\r\n Queue.apply(this, contents);\r\n }\r\n inherits(PeekableQueue, Queue);\r\n PeekableQueue.prototype.peek = function () {\r\n return this._queue[0];\r\n }\r\n\r\n // good\r\n class PeekableQueue extends Queue {\r\n peek() {\r\n return this._queue[0];\r\n }\r\n }\r\n ```\r\n\r\n - [9.3](#9.3) Methods can return `this` to help with method chaining.\r\n\r\n ```javascript\r\n // bad\r\n Jedi.prototype.jump = function () {\r\n this.jumping = true;\r\n return true;\r\n };\r\n\r\n Jedi.prototype.setHeight = function (height) {\r\n this.height = height;\r\n };\r\n\r\n const luke = new Jedi();\r\n luke.jump(); // => true\r\n luke.setHeight(20); // => undefined\r\n\r\n // good\r\n class Jedi {\r\n jump() {\r\n this.jumping = true;\r\n return this;\r\n }\r\n\r\n setHeight(height) {\r\n this.height = height;\r\n return this;\r\n }\r\n }\r\n\r\n const luke = new Jedi();\r\n\r\n luke.jump()\r\n .setHeight(20);\r\n ```\r\n\r\n\r\n - [9.4](#9.4) It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects.\r\n\r\n ```javascript\r\n class Jedi {\r\n constructor(options = {}) {\r\n this.name = options.name || 'no name';\r\n }\r\n\r\n getName() {\r\n return this.name;\r\n }\r\n\r\n toString() {\r\n return `Jedi - ${this.getName()}`;\r\n }\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Modules\r\n\r\n - [10.1](#10.1) Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system.\r\n\r\n > Why? Modules are the future, let's start using the future now.\r\n\r\n ```javascript\r\n // bad\r\n const AirbnbStyleGuide = require('./AirbnbStyleGuide');\r\n module.exports = AirbnbStyleGuide.es6;\r\n\r\n // ok\r\n import AirbnbStyleGuide from './AirbnbStyleGuide';\r\n export default AirbnbStyleGuide.es6;\r\n\r\n // best\r\n import { es6 } from './AirbnbStyleGuide';\r\n export default es6;\r\n ```\r\n\r\n - [10.2](#10.2) Do not use wildcard imports.\r\n\r\n > Why? This makes sure you have a single default export.\r\n\r\n ```javascript\r\n // bad\r\n import * as AirbnbStyleGuide from './AirbnbStyleGuide';\r\n\r\n // good\r\n import AirbnbStyleGuide from './AirbnbStyleGuide';\r\n ```\r\n\r\n - [10.3](#10.3) And do not export directly from an import.\r\n\r\n > Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent.\r\n\r\n ```javascript\r\n // bad\r\n // filename es6.js\r\n export { es6 as default } from './airbnbStyleGuide';\r\n\r\n // good\r\n // filename es6.js\r\n import { es6 } from './AirbnbStyleGuide';\r\n export default es6;\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Iterators and Generators\r\n\r\n - [11.1](#11.1) Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`.\r\n\r\n > Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects.\r\n\r\n eslint rules: [`no-iterator`](http://eslint.org/docs/rules/no-iterator.html).\r\n\r\n ```javascript\r\n const numbers = [1, 2, 3, 4, 5];\r\n\r\n // bad\r\n let sum = 0;\r\n for (let num of numbers) {\r\n sum += num;\r\n }\r\n\r\n sum === 15;\r\n\r\n // good\r\n let sum = 0;\r\n numbers.forEach((num) => sum += num);\r\n sum === 15;\r\n\r\n // best (use the functional force)\r\n const sum = numbers.reduce((total, num) => total + num, 0);\r\n sum === 15;\r\n ```\r\n\r\n - [11.2](#11.2) Don't use generators for now.\r\n\r\n > Why? They don't transpile well to ES5.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Properties\r\n\r\n - [12.1](#12.1) Use dot notation when accessing properties.\r\n\r\n eslint rules: [`dot-notation`](http://eslint.org/docs/rules/dot-notation.html).\r\n\r\n ```javascript\r\n const luke = {\r\n jedi: true,\r\n age: 28,\r\n };\r\n\r\n // bad\r\n const isJedi = luke['jedi'];\r\n\r\n // good\r\n const isJedi = luke.jedi;\r\n ```\r\n\r\n - [12.2](#12.2) Use subscript notation `[]` when accessing properties with a variable.\r\n\r\n ```javascript\r\n const luke = {\r\n jedi: true,\r\n age: 28,\r\n };\r\n\r\n function getProp(prop) {\r\n return luke[prop];\r\n }\r\n\r\n const isJedi = getProp('jedi');\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Variables\r\n\r\n - [13.1](#13.1) Always use `const` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that.\r\n\r\n ```javascript\r\n // bad\r\n superPower = new SuperPower();\r\n\r\n // good\r\n const superPower = new SuperPower();\r\n ```\r\n\r\n - [13.2](#13.2) Use one `const` declaration per variable.\r\n\r\n > Why? It's easier to add new variable declarations this way, and you never have to worry about swapping out a `;` for a `,` or introducing punctuation-only diffs.\r\n\r\n eslint rules: [`one-var`](http://eslint.org/docs/rules/one-var.html).\r\n\r\n ```javascript\r\n // bad\r\n const items = getItems(),\r\n goSportsTeam = true,\r\n dragonball = 'z';\r\n\r\n // bad\r\n // (compare to above, and try to spot the mistake)\r\n const items = getItems(),\r\n goSportsTeam = true;\r\n dragonball = 'z';\r\n\r\n // good\r\n const items = getItems();\r\n const goSportsTeam = true;\r\n const dragonball = 'z';\r\n ```\r\n\r\n - [13.3](#13.3) Group all your `const`s and then group all your `let`s.\r\n\r\n > Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.\r\n\r\n ```javascript\r\n // bad\r\n let i, len, dragonball,\r\n items = getItems(),\r\n goSportsTeam = true;\r\n\r\n // bad\r\n let i;\r\n const items = getItems();\r\n let dragonball;\r\n const goSportsTeam = true;\r\n let len;\r\n\r\n // good\r\n const goSportsTeam = true;\r\n const items = getItems();\r\n let dragonball;\r\n let i;\r\n let length;\r\n ```\r\n\r\n - [13.4](#13.4) Assign variables where you need them, but place them in a reasonable place.\r\n\r\n > Why? `let` and `const` are block scoped and not function scoped.\r\n\r\n ```javascript\r\n // good\r\n function () {\r\n test();\r\n console.log('doing stuff..');\r\n\r\n //..other stuff..\r\n\r\n const name = getName();\r\n\r\n if (name === 'test') {\r\n return false;\r\n }\r\n\r\n return name;\r\n }\r\n\r\n // bad - unnecessary function call\r\n function (hasName) {\r\n const name = getName();\r\n\r\n if (!hasName) {\r\n return false;\r\n }\r\n\r\n this.setFirstName(name);\r\n\r\n return true;\r\n }\r\n\r\n // good\r\n function (hasName) {\r\n if (!hasName) {\r\n return false;\r\n }\r\n\r\n const name = getName();\r\n this.setFirstName(name);\r\n\r\n return true;\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Hoisting\r\n\r\n - [14.1](#14.1) `var` declarations get hoisted to the top of their scope, their assignment does not. `const` and `let` declarations are blessed with a new concept called [Temporal Dead Zones (TDZ)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let). It's important to know why [typeof is no longer safe](http://es-discourse.com/t/why-typeof-is-no-longer-safe/15).\r\n\r\n ```javascript\r\n // we know this wouldn't work (assuming there\r\n // is no notDefined global variable)\r\n function example() {\r\n console.log(notDefined); // => throws a ReferenceError\r\n }\r\n\r\n // creating a variable declaration after you\r\n // reference the variable will work due to\r\n // variable hoisting. Note: the assignment\r\n // value of `true` is not hoisted.\r\n function example() {\r\n console.log(declaredButNotAssigned); // => undefined\r\n var declaredButNotAssigned = true;\r\n }\r\n\r\n // The interpreter is hoisting the variable\r\n // declaration to the top of the scope,\r\n // which means our example could be rewritten as:\r\n function example() {\r\n let declaredButNotAssigned;\r\n console.log(declaredButNotAssigned); // => undefined\r\n declaredButNotAssigned = true;\r\n }\r\n\r\n // using const and let\r\n function example() {\r\n console.log(declaredButNotAssigned); // => throws a ReferenceError\r\n console.log(typeof declaredButNotAssigned); // => throws a ReferenceError\r\n const declaredButNotAssigned = true;\r\n }\r\n ```\r\n\r\n - [14.2](#14.2) Anonymous function expressions hoist their variable name, but not the function assignment.\r\n\r\n ```javascript\r\n function example() {\r\n console.log(anonymous); // => undefined\r\n\r\n anonymous(); // => TypeError anonymous is not a function\r\n\r\n var anonymous = function () {\r\n console.log('anonymous function expression');\r\n };\r\n }\r\n ```\r\n\r\n - [14.3](#14.3) Named function expressions hoist the variable name, not the function name or the function body.\r\n\r\n ```javascript\r\n function example() {\r\n console.log(named); // => undefined\r\n\r\n named(); // => TypeError named is not a function\r\n\r\n superPower(); // => ReferenceError superPower is not defined\r\n\r\n var named = function superPower() {\r\n console.log('Flying');\r\n };\r\n }\r\n\r\n // the same is true when the function name\r\n // is the same as the variable name.\r\n function example() {\r\n console.log(named); // => undefined\r\n\r\n named(); // => TypeError named is not a function\r\n\r\n var named = function named() {\r\n console.log('named');\r\n }\r\n }\r\n ```\r\n\r\n - [14.4](#14.4) Function declarations hoist their name and the function body.\r\n\r\n ```javascript\r\n function example() {\r\n superPower(); // => Flying\r\n\r\n function superPower() {\r\n console.log('Flying');\r\n }\r\n }\r\n ```\r\n\r\n - For more information refer to [JavaScript Scoping & Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting/) by [Ben Cherry](http://www.adequatelygood.com/).\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Comparison Operators & Equality\r\n\r\n - [15.1](#15.1) Use `===` and `!==` over `==` and `!=`.\r\n - [15.2](#15.2) Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow these simple rules:\r\n\r\n eslint rules: [`eqeqeq`](http://eslint.org/docs/rules/eqeqeq.html).\r\n\r\n + **Objects** evaluate to **true**\r\n + **Undefined** evaluates to **false**\r\n + **Null** evaluates to **false**\r\n + **Booleans** evaluate to **the value of the boolean**\r\n + **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**\r\n + **Strings** evaluate to **false** if an empty string `''`, otherwise **true**\r\n\r\n ```javascript\r\n if ([0]) {\r\n // true\r\n // An array is an object, objects evaluate to true\r\n }\r\n ```\r\n\r\n - [15.3](#15.3) Use shortcuts.\r\n\r\n ```javascript\r\n // bad\r\n if (name !== '') {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n if (name) {\r\n // ...stuff...\r\n }\r\n\r\n // bad\r\n if (collection.length > 0) {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n if (collection.length) {\r\n // ...stuff...\r\n }\r\n ```\r\n\r\n - [15.4](#15.4) For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Blocks\r\n\r\n - [16.1](#16.1) Use braces with all multi-line blocks.\r\n\r\n ```javascript\r\n // bad\r\n if (test)\r\n return false;\r\n\r\n // good\r\n if (test) return false;\r\n\r\n // good\r\n if (test) {\r\n return false;\r\n }\r\n\r\n // bad\r\n function () { return false; }\r\n\r\n // good\r\n function () {\r\n return false;\r\n }\r\n ```\r\n\r\n - [16.2](#16.2) If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your\r\n `if` block's closing brace.\r\n\r\n eslint rules: [`brace-style`](http://eslint.org/docs/rules/brace-style.html).\r\n\r\n ```javascript\r\n // bad\r\n if (test) {\r\n thing1();\r\n thing2();\r\n }\r\n else {\r\n thing3();\r\n }\r\n\r\n // good\r\n if (test) {\r\n thing1();\r\n thing2();\r\n } else {\r\n thing3();\r\n }\r\n ```\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Comments\r\n\r\n - [17.1](#17.1) Use `/** ... */` for multi-line comments. Include a description, specify types and values for all parameters and return values.\r\n\r\n ```javascript\r\n // bad\r\n // make() returns a new element\r\n // based on the passed in tag name\r\n //\r\n // @param {String} tag\r\n // @return {Element} element\r\n function make(tag) {\r\n\r\n // ...stuff...\r\n\r\n return element;\r\n }\r\n\r\n // good\r\n /**\r\n * make() returns a new element\r\n * based on the passed in tag name\r\n *\r\n * @param {String} tag\r\n * @return {Element} element\r\n */\r\n function make(tag) {\r\n\r\n // ...stuff...\r\n\r\n return element;\r\n }\r\n ```\r\n\r\n - [17.2](#17.2) Use `//` for single line comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment unless it's on the first line of a block.\r\n\r\n ```javascript\r\n // bad\r\n const active = true; // is current tab\r\n\r\n // good\r\n // is current tab\r\n const active = true;\r\n\r\n // bad\r\n function getType() {\r\n console.log('fetching type...');\r\n // set the default type to 'no type'\r\n const type = this._type || 'no type';\r\n\r\n return type;\r\n }\r\n\r\n // good\r\n function getType() {\r\n console.log('fetching type...');\r\n\r\n // set the default type to 'no type'\r\n const type = this._type || 'no type';\r\n\r\n return type;\r\n }\r\n\r\n // also good\r\n function getType() {\r\n // set the default type to 'no type'\r\n const type = this._type || 'no type';\r\n\r\n return type;\r\n }\r\n ```\r\n\r\n - [17.3](#17.3) Prefixing your comments with `FIXME` or `TODO` helps other developers quickly understand if you're pointing out a problem that needs to be revisited, or if you're suggesting a solution to the problem that needs to be implemented. These are different than regular comments because they are actionable. The actions are `FIXME -- need to figure this out` or `TODO -- need to implement`.\r\n\r\n - [17.4](#17.4) Use `// FIXME:` to annotate problems.\r\n\r\n ```javascript\r\n class Calculator extends Abacus {\r\n constructor() {\r\n super();\r\n\r\n // FIXME: shouldn't use a global here\r\n total = 0;\r\n }\r\n }\r\n ```\r\n\r\n - [17.5](#17.5) Use `// TODO:` to annotate solutions to problems.\r\n\r\n ```javascript\r\n class Calculator extends Abacus {\r\n constructor() {\r\n super();\r\n\r\n // TODO: total should be configurable by an options param\r\n this.total = 0;\r\n }\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Whitespace\r\n\r\n - [18.1](#18.1) Use soft tabs set to 2 spaces.\r\n\r\n eslint rules: [`indent`](http://eslint.org/docs/rules/indent.html).\r\n\r\n ```javascript\r\n // bad\r\n function () {\r\n ∙∙∙∙const name;\r\n }\r\n\r\n // bad\r\n function () {\r\n ∙const name;\r\n }\r\n\r\n // good\r\n function () {\r\n ∙∙const name;\r\n }\r\n ```\r\n\r\n - [18.2](#18.2) Place 1 space before the leading brace.\r\n\r\n eslint rules: [`space-before-blocks`](http://eslint.org/docs/rules/space-before-blocks.html).\r\n\r\n ```javascript\r\n // bad\r\n function test(){\r\n console.log('test');\r\n }\r\n\r\n // good\r\n function test() {\r\n console.log('test');\r\n }\r\n\r\n // bad\r\n dog.set('attr',{\r\n age: '1 year',\r\n breed: 'Bernese Mountain Dog',\r\n });\r\n\r\n // good\r\n dog.set('attr', {\r\n age: '1 year',\r\n breed: 'Bernese Mountain Dog',\r\n });\r\n ```\r\n\r\n - [18.3](#18.3) Place 1 space before the opening parenthesis in control statements (`if`, `while` etc.). Place no space before the argument list in function calls and declarations.\r\n\r\n eslint rules: [`space-after-keywords`](http://eslint.org/docs/rules/space-after-keywords.html), [`space-before-keywords`](http://eslint.org/docs/rules/space-before-keywords.html).\r\n\r\n ```javascript\r\n // bad\r\n if(isJedi) {\r\n fight ();\r\n }\r\n\r\n // good\r\n if (isJedi) {\r\n fight();\r\n }\r\n\r\n // bad\r\n function fight () {\r\n console.log ('Swooosh!');\r\n }\r\n\r\n // good\r\n function fight() {\r\n console.log('Swooosh!');\r\n }\r\n ```\r\n\r\n - [18.4](#18.4) Set off operators with spaces.\r\n\r\n eslint rules: [`space-infix-ops`](http://eslint.org/docs/rules/space-infix-ops.html).\r\n\r\n ```javascript\r\n // bad\r\n const x=y+5;\r\n\r\n // good\r\n const x = y + 5;\r\n ```\r\n\r\n - [18.5](#18.5) End files with a single newline character.\r\n\r\n ```javascript\r\n // bad\r\n (function (global) {\r\n // ...stuff...\r\n })(this);\r\n ```\r\n\r\n ```javascript\r\n // bad\r\n (function (global) {\r\n // ...stuff...\r\n })(this);↵\r\n ↵\r\n ```\r\n\r\n ```javascript\r\n // good\r\n (function (global) {\r\n // ...stuff...\r\n })(this);↵\r\n ```\r\n\r\n - [18.6](#18.6) Use indentation when making long method chains. Use a leading dot, which\r\n emphasizes that the line is a method call, not a new statement.\r\n\r\n ```javascript\r\n // bad\r\n $('#items').find('.selected').highlight().end().find('.open').updateCount();\r\n\r\n // bad\r\n $('#items').\r\n find('.selected').\r\n highlight().\r\n end().\r\n find('.open').\r\n updateCount();\r\n\r\n // good\r\n $('#items')\r\n .find('.selected')\r\n .highlight()\r\n .end()\r\n .find('.open')\r\n .updateCount();\r\n\r\n // bad\r\n const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true)\r\n .attr('width', (radius + margin) * 2).append('svg:g')\r\n .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')\r\n .call(tron.led);\r\n\r\n // good\r\n const leds = stage.selectAll('.led')\r\n .data(data)\r\n .enter().append('svg:svg')\r\n .classed('led', true)\r\n .attr('width', (radius + margin) * 2)\r\n .append('svg:g')\r\n .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')\r\n .call(tron.led);\r\n ```\r\n\r\n - [18.7](#18.7) Leave a blank line after blocks and before the next statement.\r\n\r\n ```javascript\r\n // bad\r\n if (foo) {\r\n return bar;\r\n }\r\n return baz;\r\n\r\n // good\r\n if (foo) {\r\n return bar;\r\n }\r\n\r\n return baz;\r\n\r\n // bad\r\n const obj = {\r\n foo() {\r\n },\r\n bar() {\r\n },\r\n };\r\n return obj;\r\n\r\n // good\r\n const obj = {\r\n foo() {\r\n },\r\n\r\n bar() {\r\n },\r\n };\r\n\r\n return obj;\r\n\r\n // bad\r\n const arr = [\r\n function foo() {\r\n },\r\n function bar() {\r\n },\r\n ];\r\n return arr;\r\n\r\n // good\r\n const arr = [\r\n function foo() {\r\n },\r\n\r\n function bar() {\r\n },\r\n ];\r\n\r\n return arr;\r\n ```\r\n\r\n - [18.8](#18.8) Do not pad your blocks with blank lines.\r\n\r\n eslint rules: [`padded-blocks`](http://eslint.org/docs/rules/padded-blocks.html).\r\n\r\n ```javascript\r\n // bad\r\n function bar() {\r\n\r\n console.log(foo);\r\n\r\n }\r\n\r\n // also bad\r\n if (baz) {\r\n\r\n console.log(qux);\r\n } else {\r\n console.log(foo);\r\n\r\n }\r\n\r\n // good\r\n function bar() {\r\n console.log(foo);\r\n }\r\n\r\n // good\r\n if (baz) {\r\n console.log(qux);\r\n } else {\r\n console.log(foo);\r\n }\r\n ```\r\n\r\n - [18.9](#18.9) Do not add spaces inside parentheses.\r\n\r\n eslint rules: [`space-in-parens`](http://eslint.org/docs/rules/space-in-parens.html).\r\n\r\n ```javascript\r\n // bad\r\n function bar( foo ) {\r\n return foo;\r\n }\r\n\r\n // good\r\n function bar(foo) {\r\n return foo;\r\n }\r\n\r\n // bad\r\n if ( foo ) {\r\n console.log(foo);\r\n }\r\n\r\n // good\r\n if (foo) {\r\n console.log(foo);\r\n }\r\n ```\r\n\r\n - [18.10](#18.10) Do not add spaces inside brackets.\r\n\r\n eslint rules: [`array-bracket-spacing`](http://eslint.org/docs/rules/array-bracket-spacing.html).\r\n\r\n ```javascript\r\n // bad\r\n const foo = [ 1, 2, 3 ];\r\n console.log(foo[ 0 ]);\r\n\r\n // good\r\n const foo = [1, 2, 3];\r\n console.log(foo[0]);\r\n ```\r\n\r\n - [18.11](#18.11) Add spaces inside curly braces.\r\n\r\n eslint rules: [`object-curly-spacing`](http://eslint.org/docs/rules/object-curly-spacing.html).\r\n\r\n ```javascript\r\n // bad\r\n const foo = {clark: 'kent'};\r\n\r\n // good\r\n const foo = { clark: 'kent' };\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Commas\r\n\r\n - [19.1](#19.1) Leading commas: **Nope.**\r\n\r\n eslint rules: [`comma-style`](http://eslint.org/docs/rules/comma-style.html).\r\n\r\n ```javascript\r\n // bad\r\n const story = [\r\n once\r\n , upon\r\n , aTime\r\n ];\r\n\r\n // good\r\n const story = [\r\n once,\r\n upon,\r\n aTime,\r\n ];\r\n\r\n // bad\r\n const hero = {\r\n firstName: 'Ada'\r\n , lastName: 'Lovelace'\r\n , birthYear: 1815\r\n , superPower: 'computers'\r\n };\r\n\r\n // good\r\n const hero = {\r\n firstName: 'Ada',\r\n lastName: 'Lovelace',\r\n birthYear: 1815,\r\n superPower: 'computers',\r\n };\r\n ```\r\n\r\n - [19.2](#19.2) Additional trailing comma: **Yup.**\r\n\r\n eslint rules: [`no-comma-dangle`](http://eslint.org/docs/rules/no-comma-dangle.html).\r\n\r\n > Why? This leads to cleaner git diffs. Also, transpilers like Babel will remove the additional trailing comma in the transpiled code which means you don't have to worry about the [trailing comma problem](es5/README.md#commas) in legacy browsers.\r\n\r\n ```javascript\r\n // bad - git diff without trailing comma\r\n const hero = {\r\n firstName: 'Florence',\r\n - lastName: 'Nightingale'\r\n + lastName: 'Nightingale',\r\n + inventorOf: ['coxcomb graph', 'modern nursing']\r\n };\r\n\r\n // good - git diff with trailing comma\r\n const hero = {\r\n firstName: 'Florence',\r\n lastName: 'Nightingale',\r\n + inventorOf: ['coxcomb chart', 'modern nursing'],\r\n };\r\n\r\n // bad\r\n const hero = {\r\n firstName: 'Dana',\r\n lastName: 'Scully'\r\n };\r\n\r\n const heroes = [\r\n 'Batman',\r\n 'Superman'\r\n ];\r\n\r\n // good\r\n const hero = {\r\n firstName: 'Dana',\r\n lastName: 'Scully',\r\n };\r\n\r\n const heroes = [\r\n 'Batman',\r\n 'Superman',\r\n ];\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Semicolons\r\n\r\n - [20.1](#20.1) **Yup.**\r\n\r\n eslint rules: [`semi`](http://eslint.org/docs/rules/semi.html).\r\n\r\n ```javascript\r\n // bad\r\n (function () {\r\n const name = 'Skywalker'\r\n return name\r\n })()\r\n\r\n // good\r\n (() => {\r\n const name = 'Skywalker';\r\n return name;\r\n })();\r\n\r\n // good (guards against the function becoming an argument when two files with IIFEs are concatenated)\r\n ;(() => {\r\n const name = 'Skywalker';\r\n return name;\r\n })();\r\n ```\r\n\r\n [Read more](http://stackoverflow.com/questions/7365172/semicolon-before-self-invoking-function/7365214%237365214).\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Type Casting & Coercion\r\n\r\n - [21.1](#21.1) Perform type coercion at the beginning of the statement.\r\n - [21.2](#21.2) Strings:\r\n\r\n ```javascript\r\n // => this.reviewScore = 9;\r\n\r\n // bad\r\n const totalScore = this.reviewScore + '';\r\n\r\n // good\r\n const totalScore = String(this.reviewScore);\r\n ```\r\n\r\n - [21.3](#21.3) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings.\r\n\r\n ```javascript\r\n const inputValue = '4';\r\n\r\n // bad\r\n const val = new Number(inputValue);\r\n\r\n // bad\r\n const val = +inputValue;\r\n\r\n // bad\r\n const val = inputValue >> 0;\r\n\r\n // bad\r\n const val = parseInt(inputValue);\r\n\r\n // good\r\n const val = Number(inputValue);\r\n\r\n // good\r\n const val = parseInt(inputValue, 10);\r\n ```\r\n\r\n - [21.4](#21.4) If for whatever reason you are doing something wild and `parseInt` is your bottleneck and need to use Bitshift for [performance reasons](http://jsperf.com/coercion-vs-casting/3), leave a comment explaining why and what you're doing.\r\n\r\n ```javascript\r\n // good\r\n /**\r\n * parseInt was the reason my code was slow.\r\n * Bitshifting the String to coerce it to a\r\n * Number made it a lot faster.\r\n */\r\n const val = inputValue >> 0;\r\n ```\r\n\r\n - [21.5](#21.5) **Note:** Be careful when using bitshift operations. Numbers are represented as [64-bit values](http://es5.github.io/#x4.3.19), but Bitshift operations always return a 32-bit integer ([source](http://es5.github.io/#x11.7)). Bitshift can lead to unexpected behavior for integer values larger than 32 bits. [Discussion](https://github.com/airbnb/javascript/issues/109). Largest signed 32-bit Int is 2,147,483,647:\r\n\r\n ```javascript\r\n 2147483647 >> 0 //=> 2147483647\r\n 2147483648 >> 0 //=> -2147483648\r\n 2147483649 >> 0 //=> -2147483647\r\n ```\r\n\r\n - [21.6](#21.6) Booleans:\r\n\r\n ```javascript\r\n const age = 0;\r\n\r\n // bad\r\n const hasAge = new Boolean(age);\r\n\r\n // good\r\n const hasAge = Boolean(age);\r\n\r\n // good\r\n const hasAge = !!age;\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Naming Conventions\r\n\r\n - [22.1](#22.1) Avoid single letter names. Be descriptive with your naming.\r\n\r\n ```javascript\r\n // bad\r\n function q() {\r\n // ...stuff...\r\n }\r\n\r\n // good\r\n function query() {\r\n // ..stuff..\r\n }\r\n ```\r\n\r\n - [22.2](#22.2) Use camelCase when naming objects, functions, and instances.\r\n\r\n eslint rules: [`camelcase`](http://eslint.org/docs/rules/camelcase.html).\r\n\r\n ```javascript\r\n // bad\r\n const OBJEcttsssss = {};\r\n const this_is_my_object = {};\r\n function c() {}\r\n\r\n // good\r\n const thisIsMyObject = {};\r\n function thisIsMyFunction() {}\r\n ```\r\n\r\n - [22.3](#22.3) Use PascalCase when naming constructors or classes.\r\n\r\n ```javascript\r\n // bad\r\n function user(options) {\r\n this.name = options.name;\r\n }\r\n\r\n const bad = new user({\r\n name: 'nope',\r\n });\r\n\r\n // good\r\n class User {\r\n constructor(options) {\r\n this.name = options.name;\r\n }\r\n }\r\n\r\n const good = new User({\r\n name: 'yup',\r\n });\r\n ```\r\n\r\n - [22.4](#22.4) Use a leading underscore `_` when naming private properties.\r\n\r\n eslint rules: [`no-underscore-dangle`](http://eslint.org/docs/rules/no-underscore-dangle.html).\r\n\r\n ```javascript\r\n // bad\r\n this.__firstName__ = 'Panda';\r\n this.firstName_ = 'Panda';\r\n\r\n // good\r\n this._firstName = 'Panda';\r\n ```\r\n\r\n - [22.5](#22.5) Don't save references to `this`. Use arrow functions or Function#bind.\r\n\r\n ```javascript\r\n // bad\r\n function foo() {\r\n const self = this;\r\n return function () {\r\n console.log(self);\r\n };\r\n }\r\n\r\n // bad\r\n function foo() {\r\n const that = this;\r\n return function () {\r\n console.log(that);\r\n };\r\n }\r\n\r\n // good\r\n function foo() {\r\n return () => {\r\n console.log(this);\r\n };\r\n }\r\n ```\r\n\r\n - [22.6](#22.6) If your file exports a single class, your filename should be exactly the name of the class.\r\n\r\n ```javascript\r\n // file contents\r\n class CheckBox {\r\n // ...\r\n }\r\n export default CheckBox;\r\n\r\n // in some other file\r\n // bad\r\n import CheckBox from './checkBox';\r\n\r\n // bad\r\n import CheckBox from './check_box';\r\n\r\n // good\r\n import CheckBox from './CheckBox';\r\n ```\r\n\r\n - [22.7](#22.7) Use camelCase when you export-default a function. Your filename should be identical to your function's name.\r\n\r\n ```javascript\r\n function makeStyleGuide() {\r\n }\r\n\r\n export default makeStyleGuide;\r\n ```\r\n\r\n - [22.8](#22.8) Use PascalCase when you export a singleton / function library / bare object.\r\n\r\n ```javascript\r\n const AirbnbStyleGuide = {\r\n es6: {\r\n }\r\n };\r\n\r\n export default AirbnbStyleGuide;\r\n ```\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Accessors\r\n\r\n - [23.1](#23.1) Accessor functions for properties are not required.\r\n - [23.2](#23.2) If you do make accessor functions use getVal() and setVal('hello').\r\n\r\n ```javascript\r\n // bad\r\n dragon.age();\r\n\r\n // good\r\n dragon.getAge();\r\n\r\n // bad\r\n dragon.age(25);\r\n\r\n // good\r\n dragon.setAge(25);\r\n ```\r\n\r\n - [23.3](#23.3) If the property is a `boolean`, use `isVal()` or `hasVal()`.\r\n\r\n ```javascript\r\n // bad\r\n if (!dragon.age()) {\r\n return false;\r\n }\r\n\r\n // good\r\n if (!dragon.hasAge()) {\r\n return false;\r\n }\r\n ```\r\n\r\n - [23.4](#23.4) It's okay to create get() and set() functions, but be consistent.\r\n\r\n ```javascript\r\n class Jedi {\r\n constructor(options = {}) {\r\n const lightsaber = options.lightsaber || 'blue';\r\n this.set('lightsaber', lightsaber);\r\n }\r\n\r\n set(key, val) {\r\n this[key] = val;\r\n }\r\n\r\n get(key) {\r\n return this[key];\r\n }\r\n }\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Events\r\n\r\n - [24.1](#24.1) When attaching data payloads to events (whether DOM events or something more proprietary like Backbone events), pass a hash instead of a raw value. This allows a subsequent contributor to add more data to the event payload without finding and updating every handler for the event. For example, instead of:\r\n\r\n ```javascript\r\n // bad\r\n $(this).trigger('listingUpdated', listing.id);\r\n\r\n ...\r\n\r\n $(this).on('listingUpdated', function (e, listingId) {\r\n // do something with listingId\r\n });\r\n ```\r\n\r\n prefer:\r\n\r\n ```javascript\r\n // good\r\n $(this).trigger('listingUpdated', { listingId: listing.id });\r\n\r\n ...\r\n\r\n $(this).on('listingUpdated', function (e, data) {\r\n // do something with data.listingId\r\n });\r\n ```\r\n\r\n **[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## jQuery\r\n\r\n - [25.1](#25.1) Prefix jQuery object variables with a `$`.\r\n\r\n ```javascript\r\n // bad\r\n const sidebar = $('.sidebar');\r\n\r\n // good\r\n const $sidebar = $('.sidebar');\r\n\r\n // good\r\n const $sidebarBtn = $('.sidebar-btn');\r\n ```\r\n\r\n - [25.2](#25.2) Cache jQuery lookups.\r\n\r\n ```javascript\r\n // bad\r\n function setSidebar() {\r\n $('.sidebar').hide();\r\n\r\n // ...stuff...\r\n\r\n $('.sidebar').css({\r\n 'background-color': 'pink'\r\n });\r\n }\r\n\r\n // good\r\n function setSidebar() {\r\n const $sidebar = $('.sidebar');\r\n $sidebar.hide();\r\n\r\n // ...stuff...\r\n\r\n $sidebar.css({\r\n 'background-color': 'pink'\r\n });\r\n }\r\n ```\r\n\r\n - [25.3](#25.3) For DOM queries use Cascading `$('.sidebar ul')` or parent > child `$('.sidebar > ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)\r\n - [25.4](#25.4) Use `find` with scoped jQuery object queries.\r\n\r\n ```javascript\r\n // bad\r\n $('ul', '.sidebar').hide();\r\n\r\n // bad\r\n $('.sidebar').find('ul').hide();\r\n\r\n // good\r\n $('.sidebar ul').hide();\r\n\r\n // good\r\n $('.sidebar > ul').hide();\r\n\r\n // good\r\n $sidebar.find('ul').hide();\r\n ```\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## ECMAScript 5 Compatibility\r\n\r\n - [26.1](#26.1) Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.io/es5-compat-table/).\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## ECMAScript 6 Styles\r\n\r\n - [27.1](#27.1) This is a collection of links to the various es6 features.\r\n\r\n1. [Arrow Functions](#arrow-functions)\r\n1. [Classes](#constructors)\r\n1. [Object Shorthand](#es6-object-shorthand)\r\n1. [Object Concise](#es6-object-concise)\r\n1. [Object Computed Properties](#es6-computed-properties)\r\n1. [Template Strings](#es6-template-literals)\r\n1. [Destructuring](#destructuring)\r\n1. [Default Parameters](#es6-default-parameters)\r\n1. [Rest](#es6-rest)\r\n1. [Array Spreads](#es6-array-spreads)\r\n1. [Let and Const](#references)\r\n1. [Iterators and Generators](#iterators-and-generators)\r\n1. [Modules](#modules)\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Testing\r\n\r\n - [28.1](#28.1) **Yup.**\r\n\r\n ```javascript\r\n function () {\r\n return true;\r\n }\r\n ```\r\n\r\n - [28.2](#28.2) **No, but seriously**:\r\n - Whichever testing framework you use, you should be writing tests!\r\n - Strive to write many small pure functions, and minimize where mutations occur.\r\n - Be cautious about stubs and mocks - they can make your tests more brittle.\r\n - We primarily use [`mocha`](https://www.npmjs.com/package/mocha) at Airbnb. [`tape`](https://www.npmjs.com/package/tape) is also used occasionally for small, separate modules.\r\n - 100% test coverage is a good goal to strive for, even if it's not always practical to reach it.\r\n - Whenever you fix a bug, _write a regression test_. A bug fixed without a regression test is almost certainly going to break again in the future.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Performance\r\n\r\n - [On Layout & Web Performance](http://www.kellegous.com/j/2013/01/26/layout-performance/)\r\n - [String vs Array Concat](http://jsperf.com/string-vs-array-concat/2)\r\n - [Try/Catch Cost In a Loop](http://jsperf.com/try-catch-in-loop-cost)\r\n - [Bang Function](http://jsperf.com/bang-function)\r\n - [jQuery Find vs Context, Selector](http://jsperf.com/jquery-find-vs-context-sel/13)\r\n - [innerHTML vs textContent for script text](http://jsperf.com/innerhtml-vs-textcontent-for-script-text)\r\n - [Long String Concatenation](http://jsperf.com/ya-string-concat)\r\n - Loading...\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n\r\n## Resources\r\n\r\n**Learning ES6**\r\n\r\n - [Draft ECMA 2015 (ES6) Spec](https://people.mozilla.org/~jorendorff/es6-draft.html)\r\n - [ExploringJS](http://exploringjs.com/)\r\n - [ES6 Compatibility Table](https://kangax.github.io/compat-table/es6/)\r\n - [Comprehensive Overview of ES6 Features](http://es6-features.org/)\r\n\r\n**Read This**\r\n\r\n - [Standard ECMA-262](http://www.ecma-international.org/ecma-262/6.0/index.html)\r\n\r\n**Tools**\r\n\r\n - Code Style Linters\r\n + [ESlint](http://eslint.org/) - [Airbnb Style .eslintrc](https://github.com/airbnb/javascript/blob/master/linters/.eslintrc)\r\n + [JSHint](http://jshint.com/) - [Airbnb Style .jshintrc](https://github.com/airbnb/javascript/blob/master/linters/jshintrc)\r\n + [JSCS](https://github.com/jscs-dev/node-jscs) - [Airbnb Style Preset](https://github.com/jscs-dev/node-jscs/blob/master/presets/airbnb.json)\r\n\r\n**Other Style Guides**\r\n\r\n - [Google JavaScript Style Guide](http://google-styleguide.googlecode.com/svn/trunk/javascriptguide.xml)\r\n - [jQuery Core Style Guidelines](http://contribute.jquery.org/style-guide/js/)\r\n - [Principles of Writing Consistent, Idiomatic JavaScript](https://github.com/rwaldron/idiomatic.js)\r\n\r\n**Other Styles**\r\n\r\n - [Naming this in nested functions](https://gist.github.com/cjohansen/4135065) - Christian Johansen\r\n - [Conditional Callbacks](https://github.com/airbnb/javascript/issues/52) - Ross Allen\r\n - [Popular JavaScript Coding Conventions on Github](http://sideeffect.kr/popularconvention/#javascript) - JeongHoon Byun\r\n - [Multiple var statements in JavaScript, not superfluous](http://benalman.com/news/2012/05/multiple-var-statements-javascript/) - Ben Alman\r\n\r\n**Further Reading**\r\n\r\n - [Understanding JavaScript Closures](http://javascriptweblog.wordpress.com/2010/10/25/understanding-javascript-closures/) - Angus Croll\r\n - [Basic JavaScript for the impatient programmer](http://www.2ality.com/2013/06/basic-javascript.html) - Dr. Axel Rauschmayer\r\n - [You Might Not Need jQuery](http://youmightnotneedjquery.com/) - Zack Bloom & Adam Schwartz\r\n - [ES6 Features](https://github.com/lukehoban/es6features) - Luke Hoban\r\n - [Frontend Guidelines](https://github.com/bendc/frontend-guidelines) - Benjamin De Cock\r\n\r\n**Books**\r\n\r\n - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford\r\n - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov\r\n - [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X) - Ross Harmes and Dustin Diaz\r\n - [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders\r\n - [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas\r\n - [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw\r\n - [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig\r\n - [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch\r\n - [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault\r\n - [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg\r\n - [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, & Olav Bjorkoy\r\n - [JSBooks](http://jsbooks.revolunet.com/) - Julien Bouquillon\r\n - [Third Party JavaScript](https://www.manning.com/books/third-party-javascript) - Ben Vinegar and Anton Kovalyov\r\n - [Effective JavaScript: 68 Specific Ways to Harness the Power of JavaScript](http://amzn.com/0321812182) - David Herman\r\n - [Eloquent JavaScript](http://eloquentjavascript.net/) - Marijn Haverbeke\r\n - [You Don't Know JS: ES6 & Beyond](http://shop.oreilly.com/product/0636920033769.do) - Kyle Simpson\r\n\r\n**Blogs**\r\n\r\n - [DailyJS](http://dailyjs.com/)\r\n - [JavaScript Weekly](http://javascriptweekly.com/)\r\n - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)\r\n - [Bocoup Weblog](https://bocoup.com/weblog)\r\n - [Adequately Good](http://www.adequatelygood.com/)\r\n - [NCZOnline](https://www.nczonline.net/)\r\n - [Perfection Kills](http://perfectionkills.com/)\r\n - [Ben Alman](http://benalman.com/)\r\n - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)\r\n - [Dustin Diaz](http://dustindiaz.com/)\r\n - [nettuts](http://code.tutsplus.com/?s=javascript)\r\n\r\n**Podcasts**\r\n\r\n - [JavaScript Jabber](https://devchat.tv/js-jabber/)\r\n\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## In the Wild\r\n\r\n 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.\r\n\r\n - **Aan Zee**: [AanZee/javascript](https://github.com/AanZee/javascript)\r\n - **Adult Swim**: [adult-swim/javascript](https://github.com/adult-swim/javascript)\r\n - **Airbnb**: [airbnb/javascript](https://github.com/airbnb/javascript)\r\n - **Apartmint**: [apartmint/javascript](https://github.com/apartmint/javascript)\r\n - **Avalara**: [avalara/javascript](https://github.com/avalara/javascript)\r\n - **Billabong**: [billabong/javascript](https://github.com/billabong/javascript)\r\n - **Bisk**: [bisk/javascript](https://github.com/Bisk/javascript/)\r\n - **Blendle**: [blendle/javascript](https://github.com/blendle/javascript)\r\n - **ComparaOnline**: [comparaonline/javascript](https://github.com/comparaonline/javascript-style-guide)\r\n - **Compass Learning**: [compasslearning/javascript-style-guide](https://github.com/compasslearning/javascript-style-guide)\r\n - **DailyMotion**: [dailymotion/javascript](https://github.com/dailymotion/javascript)\r\n - **Digitpaint** [digitpaint/javascript](https://github.com/digitpaint/javascript)\r\n - **Ecosia**: [ecosia/javascript](https://github.com/ecosia/javascript)\r\n - **Evernote**: [evernote/javascript-style-guide](https://github.com/evernote/javascript-style-guide)\r\n - **ExactTarget**: [ExactTarget/javascript](https://github.com/ExactTarget/javascript)\r\n - **Expensify** [Expensify/Style-Guide](https://github.com/Expensify/Style-Guide/blob/master/javascript.md)\r\n - **Flexberry**: [Flexberry/javascript-style-guide](https://github.com/Flexberry/javascript-style-guide)\r\n - **Gawker Media**: [gawkermedia/javascript](https://github.com/gawkermedia/javascript)\r\n - **General Electric**: [GeneralElectric/javascript](https://github.com/GeneralElectric/javascript)\r\n - **GoodData**: [gooddata/gdc-js-style](https://github.com/gooddata/gdc-js-style)\r\n - **Grooveshark**: [grooveshark/javascript](https://github.com/grooveshark/javascript)\r\n - **How About We**: [howaboutwe/javascript](https://github.com/howaboutwe/javascript-style-guide)\r\n - **Huballin**: [huballin/javascript](https://github.com/huballin/javascript)\r\n - **HubSpot**: [HubSpot/javascript](https://github.com/HubSpot/javascript)\r\n - **Hyper**: [hyperoslo/javascript-playbook](https://github.com/hyperoslo/javascript-playbook/blob/master/style.md)\r\n - **InfoJobs**: [InfoJobs/JavaScript-Style-Guide](https://github.com/InfoJobs/JavaScript-Style-Guide)\r\n - **Intent Media**: [intentmedia/javascript](https://github.com/intentmedia/javascript)\r\n - **Jam3**: [Jam3/Javascript-Code-Conventions](https://github.com/Jam3/Javascript-Code-Conventions)\r\n - **JeopardyBot**: [kesne/jeopardy-bot](https://github.com/kesne/jeopardy-bot/blob/master/STYLEGUIDE.md)\r\n - **JSSolutions**: [JSSolutions/javascript](https://github.com/JSSolutions/javascript)\r\n - **Kinetica Solutions**: [kinetica/javascript](https://github.com/kinetica/Javascript-style-guide)\r\n - **Mighty Spring**: [mightyspring/javascript](https://github.com/mightyspring/javascript)\r\n - **MinnPost**: [MinnPost/javascript](https://github.com/MinnPost/javascript)\r\n - **MitocGroup**: [MitocGroup/javascript](https://github.com/MitocGroup/javascript)\r\n - **ModCloth**: [modcloth/javascript](https://github.com/modcloth/javascript)\r\n - **Money Advice Service**: [moneyadviceservice/javascript](https://github.com/moneyadviceservice/javascript)\r\n - **Muber**: [muber/javascript](https://github.com/muber/javascript)\r\n - **National Geographic**: [natgeo/javascript](https://github.com/natgeo/javascript)\r\n - **National Park Service**: [nationalparkservice/javascript](https://github.com/nationalparkservice/javascript)\r\n - **Nimbl3**: [nimbl3/javascript](https://github.com/nimbl3/javascript)\r\n - **Orion Health**: [orionhealth/javascript](https://github.com/orionhealth/javascript)\r\n - **Peerby**: [Peerby/javascript](https://github.com/Peerby/javascript)\r\n - **Razorfish**: [razorfish/javascript-style-guide](https://github.com/razorfish/javascript-style-guide)\r\n - **reddit**: [reddit/styleguide/javascript](https://github.com/reddit/styleguide/tree/master/javascript)\r\n - **React**: [/facebook/react/blob/master/CONTRIBUTING.md#style-guide](https://github.com/facebook/react/blob/master/CONTRIBUTING.md#style-guide)\r\n - **REI**: [reidev/js-style-guide](https://github.com/reidev/js-style-guide)\r\n - **Ripple**: [ripple/javascript-style-guide](https://github.com/ripple/javascript-style-guide)\r\n - **SeekingAlpha**: [seekingalpha/javascript-style-guide](https://github.com/seekingalpha/javascript-style-guide)\r\n - **Shutterfly**: [shutterfly/javascript](https://github.com/shutterfly/javascript)\r\n - **Springload**: [springload/javascript](https://github.com/springload/javascript)\r\n - **StudentSphere**: [studentsphere/javascript](https://github.com/studentsphere/guide-javascript)\r\n - **Target**: [target/javascript](https://github.com/target/javascript)\r\n - **TheLadders**: [TheLadders/javascript](https://github.com/TheLadders/javascript)\r\n - **T4R Technology**: [T4R-Technology/javascript](https://github.com/T4R-Technology/javascript)\r\n - **VoxFeed**: [VoxFeed/javascript-style-guide](https://github.com/VoxFeed/javascript-style-guide)\r\n - **Weggo**: [Weggo/javascript](https://github.com/Weggo/javascript)\r\n - **Zillow**: [zillow/javascript](https://github.com/zillow/javascript)\r\n - **ZocDoc**: [ZocDoc/javascript](https://github.com/ZocDoc/javascript)\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Translation\r\n\r\n This style guide is also available in other languages:\r\n\r\n -  **Brazilian Portuguese**: [armoucar/javascript-style-guide](https://github.com/armoucar/javascript-style-guide)\r\n -  **Bulgarian**: [borislavvv/javascript](https://github.com/borislavvv/javascript)\r\n -  **Catalan**: [fpmweb/javascript-style-guide](https://github.com/fpmweb/javascript-style-guide)\r\n -  **Chinese (Simplified)**: [sivan/javascript-style-guide](https://github.com/sivan/javascript-style-guide)\r\n -  **Chinese (Traditional)**: [jigsawye/javascript](https://github.com/jigsawye/javascript)\r\n -  **French**: [nmussy/javascript-style-guide](https://github.com/nmussy/javascript-style-guide)\r\n -  **German**: [timofurrer/javascript-style-guide](https://github.com/timofurrer/javascript-style-guide)\r\n -  **Italian**: [sinkswim/javascript-style-guide](https://github.com/sinkswim/javascript-style-guide)\r\n -  **Japanese**: [mitsuruog/javacript-style-guide](https://github.com/mitsuruog/javacript-style-guide)\r\n -  **Korean**: [tipjs/javascript-style-guide](https://github.com/tipjs/javascript-style-guide)\r\n -  **Polish**: [mjurczyk/javascript](https://github.com/mjurczyk/javascript)\r\n -  **Russian**: [uprock/javascript](https://github.com/uprock/javascript)\r\n -  **Spanish**: [paolocarrasco/javascript-style-guide](https://github.com/paolocarrasco/javascript-style-guide)\r\n -  **Thai**: [lvarayut/javascript-style-guide](https://github.com/lvarayut/javascript-style-guide)\r\n\r\n## The JavaScript Style Guide Guide\r\n\r\n - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)\r\n\r\n## Chat With Us About JavaScript\r\n\r\n - Find us on [gitter](https://gitter.im/airbnb/javascript).\r\n\r\n## Contributors\r\n\r\n - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)\r\n\r\n\r\n## License\r\n\r\n(The MIT License)\r\n\r\nCopyright (c) 2014 Airbnb\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining\r\na copy of this software and associated documentation files (the\r\n'Software'), to deal in the Software without restriction, including\r\nwithout limitation the rights to use, copy, modify, merge, publish,\r\ndistribute, sublicense, and/or sell copies of the Software, and to\r\npermit persons to whom the Software is furnished to do so, subject to\r\nthe following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\r\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\r\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\r\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\r\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n\r\n**[⬆ back to top](#table-of-contents)**\r\n\r\n## Amendments\r\n\r\nWe 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.\r\n\r\n# };","google":"","note":"Don't delete this file! It's used internally to help with page regeneration."} \ No newline at end of file