{"id":14954595,"url":"https://github.com/meteor/javascript","last_synced_at":"2025-10-03T06:31:24.113Z","repository":{"id":34176055,"uuid":"38025065","full_name":"meteor/javascript","owner":"meteor","description":"JavaScript Style Guide","archived":false,"fork":true,"pushed_at":"2017-11-12T14:59:54.000Z","size":671,"stargazers_count":25,"open_issues_count":2,"forks_count":14,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-09-19T16:12:25.962Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"airbnb/javascript","license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/meteor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-25T03:11:54.000Z","updated_at":"2024-03-09T21:39:48.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/meteor/javascript","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/meteor/javascript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fjavascript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fjavascript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fjavascript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fjavascript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/meteor","download_url":"https://codeload.github.com/meteor/javascript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/meteor%2Fjavascript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278124738,"owners_count":25933961,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-03T02:00:06.070Z","response_time":53,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-09-24T13:04:23.532Z","updated_at":"2025-10-03T06:31:23.845Z","avatar_url":"https://github.com/meteor.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gitter](https://badges.gitter.im/Join Chat.svg)](https://gitter.im/airbnb/javascript?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge)\n\n# Airbnb JavaScript Style Guide, Meteor edition\n\n*A mostly reasonable approach to JavaScript, with some Meteor flavor*\n\nAll rules that are automatically linted have the ESLint logo, with a link to the rule, like so: \u003ca href=\"http://eslint.org/\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n\n## Table of Contents\n\n  1. [Types](#types)\n  1. [References](#references)\n  1. [Objects](#objects)\n  1. [Arrays](#arrays)\n  1. [Destructuring](#destructuring)\n  1. [Strings](#strings)\n  1. [Functions](#functions)\n  1. [Arrow Functions](#arrow-functions)\n  1. [Constructors](#constructors)\n  1. [Modules](#modules)\n  1. [Iterators and Generators](#iterators-and-generators)\n  1. [Properties](#properties)\n  1. [Variables](#variables)\n  1. [Hoisting](#hoisting)\n  1. [Comparison Operators \u0026 Equality](#comparison-operators--equality)\n  1. [Blocks](#blocks)\n  1. [Comments](#comments)\n  1. [Whitespace](#whitespace)\n  1. [Commas](#commas)\n  1. [Semicolons](#semicolons)\n  1. [Type Casting \u0026 Coercion](#type-casting--coercion)\n  1. [Naming Conventions](#naming-conventions)\n  1. [Accessors](#accessors)\n  1. [Events](#events)\n  1. [jQuery](#jquery)\n  1. [ECMAScript 5 Compatibility](#ecmascript-5-compatibility)\n  1. [ECMAScript 6 Styles](#ecmascript-6-styles)\n  1. [Testing (in AirBnB guide)](https://github.com/airbnb/javascript#testing)\n  1. [Performance (in AirBnB guide)](https://github.com/airbnb/javascript#performance)\n  1. [Resources (in AirBnB guide)](https://github.com/airbnb/javascript#resources)\n  1. [In the Wild (in AirBnB guide)](https://github.com/airbnb/javascript#in-the-wild)\n  1. [Translation (in AirBnB guide)](https://github.com/airbnb/javascript#translation)\n  1. [The JavaScript Style Guide Guide (in AirBnB guide)](https://github.com/airbnb/javascript#the-javascript-style-guide-guide)\n  1. [Chat With Us About Javascript (in AirBnB guide)](https://github.com/airbnb/javascript#chat-with-us-about-javascript)\n  1. [Contributors](#contributors)\n  1. [License](#license)\n\n## Types\n\nThis section has been eliminated in the Meteor version, because it does not specify any style rules.\n\n## References\n\n  - [2.1](#2.1) \u003ca name='2.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/no-var\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use `const` for all of your references; avoid using `var`.\n\n  \u003e Why? This ensures that you can't reassign your references (mutation), which can lead to bugs and difficult to comprehend code.\n\n    ```javascript\n    // bad\n    var a = 1;\n    var b = 2;\n\n    // good\n    const a = 1;\n    const b = 2;\n    ```\n\n  - [2.2](#2.2) \u003ca name='2.2'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/no-var\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    If you must mutate references, use `let` instead of `var`.\n\n  \u003e Why? `let` is block-scoped rather than function-scoped like `var`.\n\n    ```javascript\n    // bad\n    var count = 1;\n    if (true) {\n      count += 1;\n    }\n\n    // good, use the let.\n    let count = 1;\n    if (true) {\n      count += 1;\n    }\n    ```\n\n  - [2.3](#2.3) \u003ca name='2.3'\u003e\u003c/a\u003e This section removed in the Meteor edition, because it does not specify any style rules.\n\n**[⬆ back to top](#table-of-contents)**\n\n## Objects\n\n  - [3.1](#3.1) \u003ca name='3.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/no-new-object\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use the literal syntax for object creation.\n\n    ```javascript\n    // bad\n    const item = new Object();\n\n    // good\n    const item = {};\n    ```\n\n  - [3.2](#3.2) \u003ca name='3.2'\u003e\u003c/a\u003e and [3.3](#3.3) \u003ca name='3.3'\u003e\u003c/a\u003e eliminated in the Meteor edition because Babel can compile reserved words to work fine in old browsers.\n\n  \u003ca name=\"es6-computed-properties\"\u003e\u003c/a\u003e\n  - [3.4](#3.4) \u003ca name='3.4'\u003e\u003c/a\u003e Use computed property names when creating objects with dynamic property names.\n\n  \u003e Why? They allow you to define all the properties of an object in one place.\n\n    ```javascript\n\n    function getKey(k) {\n      return `a key named ${k}`;\n    }\n\n    // bad\n    const obj = {\n      id: 5,\n      name: 'San Francisco',\n    };\n    obj[getKey('enabled')] = true;\n\n    // good\n    const obj = {\n      id: 5,\n      name: 'San Francisco',\n      [getKey('enabled')]: true,\n    };\n    ```\n\n  \u003ca name=\"es6-object-shorthand\"\u003e\u003c/a\u003e\n  - [3.5](#3.5) \u003ca name='3.5'\u003e\u003c/a\u003e Use object method shorthand.\n\n    ```javascript\n    // bad\n    const atom = {\n      value: 1,\n\n      addValue: function (value) {\n        return atom.value + value;\n      },\n    };\n\n    // good\n    const atom = {\n      value: 1,\n\n      addValue(value) {\n        return atom.value + value;\n      },\n    };\n    ```\n\n  \u003ca name=\"es6-object-concise\"\u003e\u003c/a\u003e\n  - [3.6](#3.6) \u003ca name='3.6'\u003e\u003c/a\u003e Use property value shorthand.\n\n  \u003e Why? It is shorter to write and descriptive.\n\n    ```javascript\n    const lukeSkywalker = 'Luke Skywalker';\n\n    // bad\n    const obj = {\n      lukeSkywalker: lukeSkywalker,\n    };\n\n    // good\n    const obj = {\n      lukeSkywalker,\n    };\n    ```\n\n  - [3.7](#3.7) \u003ca name='3.7'\u003e\u003c/a\u003e Group your shorthand properties at the beginning of your object declaration.\n\n  \u003e Why? It's easier to tell which properties are using the shorthand.\n\n    ```javascript\n    const anakinSkywalker = 'Anakin Skywalker';\n    const lukeSkywalker = 'Luke Skywalker';\n\n    // bad\n    const obj = {\n      episodeOne: 1,\n      twoJedisWalkIntoACantina: 2,\n      lukeSkywalker,\n      episodeThree: 3,\n      mayTheFourth: 4,\n      anakinSkywalker,\n    };\n\n    // good\n    const obj = {\n      lukeSkywalker,\n      anakinSkywalker,\n      episodeOne: 1,\n      twoJedisWalkIntoACantina: 2,\n      episodeThree: 3,\n      mayTheFourth: 4,\n    };\n    ```\n\n  - [3.8](#3.8) \u003ca name='3.8'\u003e\u003c/a\u003e Use object spreads `...` to copy objects.\n\n    ```javascript\n    // bad\n    const copy = {};\n    Object.keys(obj).forEach((key) =\u003e {\n      copy[key] = obj[key];\n    });\n\n    // bad\n    const copy = {};\n    for (var key in obj) {\n      if (Object.prototype.hasOwnProperty.call(obj, key)) {\n        copy[key] = obj[key];\n      }\n    }\n\n    // good\n    const copy = { ...obj };\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Arrays\n\n  - [4.1](#4.1) \u003ca name='4.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/no-array-constructor\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use the literal syntax for array creation.\n\n    ```javascript\n    // bad\n    const items = new Array();\n\n    // good\n    const items = [];\n    ```\n\n  - [4.2](#4.2) \u003ca name='4.2'\u003e\u003c/a\u003e Use Array#push instead of direct assignment to add items to an array.\n\n    ```javascript\n    const someStack = [];\n\n\n    // bad\n    someStack[someStack.length] = 'abracadabra';\n\n    // good\n    someStack.push('abracadabra');\n    ```\n\n  \u003ca name=\"es6-array-spreads\"\u003e\u003c/a\u003e\n  - [4.3](#4.3) \u003ca name='4.3'\u003e\u003c/a\u003e Use array spreads `...` to copy arrays.\n\n    ```javascript\n    // bad\n    const len = items.length;\n    const itemsCopy = [];\n    let i;\n\n    for (i = 0; i \u003c len; i++) {\n      itemsCopy[i] = items[i];\n    }\n\n    // good\n    const itemsCopy = [...items];\n    ```\n  - [4.4](#4.4) \u003ca name='4.4'\u003e\u003c/a\u003e To convert an array-like object to an array, use Array#from.\n\n    ```javascript\n    const foo = document.querySelectorAll('.foo');\n    const nodes = Array.from(foo);\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Destructuring\n\n  - [5.1](#5.1) \u003ca name='5.1'\u003e\u003c/a\u003e Use object destructuring when accessing and using multiple properties of an object.\n\n  \u003e Why? Destructuring saves you from creating temporary references for those properties.\n\n    ```javascript\n    // bad\n    function getFullName(user) {\n      const firstName = user.firstName;\n      const lastName = user.lastName;\n\n      return `${firstName} ${lastName}`;\n    }\n\n    // good\n    function getFullName(obj) {\n      const { firstName, lastName } = obj;\n      return `${firstName} ${lastName}`;\n    }\n\n    // best\n    function getFullName({ firstName, lastName }) {\n      return `${firstName} ${lastName}`;\n    }\n    ```\n\n  - [5.2](#5.2) \u003ca name='5.2'\u003e\u003c/a\u003e Use array destructuring.\n\n    ```javascript\n    const arr = [1, 2, 3, 4];\n\n    // bad\n    const first = arr[0];\n    const second = arr[1];\n\n    // good\n    const [first, second] = arr;\n    ```\n\n  - [5.3](#5.3) \u003ca name='5.3'\u003e\u003c/a\u003e Use object destructuring for multiple return values, not array destructuring.\n\n  \u003e Why? You can add new properties over time or change the order of things without breaking call sites.\n\n    ```javascript\n    // bad\n    function processInput(input) {\n      // then a miracle occurs\n      return [left, right, top, bottom];\n    }\n\n    // the caller needs to think about the order of return data\n    const [left, __, top] = processInput(input);\n\n    // good\n    function processInput(input) {\n      // then a miracle occurs\n      return { left, right, top, bottom };\n    }\n\n    // the caller selects only the data they need\n    const { left, right } = processInput(input);\n    ```\n\n\n**[⬆ back to top](#table-of-contents)**\n\n## Strings\n\n  - [6.1](#6.1) \u003ca name='6.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/quotes\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use single quotes `''` for strings.\n\n    ```javascript\n    // bad\n    const name = \"Capt. Janeway\";\n\n    // good\n    const name = 'Capt. Janeway';\n    ```\n\n  - [6.2](#6.2) \u003ca name='6.2'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/max-len\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Single-line strings longer than 80 characters should be written across multiple lines using string concatenation. If you are writing a multiline string, use template strings as in [6.4](#6.4). This is a change in the Meteor edition. Note: If overused, long strings with concatenation could impact performance. [jsPerf](http://jsperf.com/ya-string-concat) \u0026 [Discussion](https://github.com/airbnb/javascript/issues/40).\n\n    ```javascript\n    // bad\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.';\n\n    // bad\n    const errorMessage = 'This is a super long error that was thrown because \\\n    of Batman. When you stop to think about how Batman had anything to do \\\n    with this, you would get nowhere \\\n    fast.';\n\n    // good\n    const errorMessage = 'This is a super long error that was thrown because ' +\n      'of Batman. When you stop to think about how Batman had anything to do ' +\n      'with this, you would get nowhere fast.';\n    ```\n\n   - [6.3](#6.3) \u003ca name='6.3'\u003e\u003c/a\u003e This non-rule merged as a note into the previous rule in the Meteor edition.\n\n  \u003ca name=\"es6-template-literals\"\u003e\u003c/a\u003e\n  - [6.4](#6.4) \u003ca name='6.4'\u003e\u003c/a\u003e When programmatically building up strings, use template strings instead of concatenation.\n\n  \u003e Why? Template strings give you a readable, concise syntax with proper newlines and string interpolation features.\n\n    ```javascript\n    // bad\n    function sayHi(name) {\n      return 'How are you, ' + name + '?';\n    }\n\n    // bad\n    function sayHi(name) {\n      return ['How are you, ', name, '?'].join();\n    }\n\n    // good\n    function sayHi(name) {\n      return `How are you, ${name}?`;\n    }\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Functions\n\n  - [7.1](#7.1) \u003ca name='7.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/func-style\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use function declarations instead of function expressions.\n\n  \u003e 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.\n\n    ```javascript\n    // bad\n    const foo = function () {\n    };\n\n    // good\n    function foo() {\n    }\n    ```\n\n  - [7.2](#7.2) \u003ca name='7.2'\u003e\u003c/a\u003e Removed in the Meteor edition.\n  - [7.3](#7.3) \u003ca name='7.3'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/no-inner-declarations\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    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. [7.4](#7.4) \u003ca name='7.4'\u003e\u003c/a\u003e **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). This note merged into the previous rule in the Meteor edition.\n\n    ```javascript\n    // bad\n    if (currentUser) {\n      function test() {\n        console.log('Nope.');\n      }\n    }\n\n    // good\n    let test;\n    if (currentUser) {\n      test = () =\u003e {\n        console.log('Yup.');\n      };\n    }\n    ```\n\n  - [7.5](#7.5) \u003ca name='7.5'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/no-shadow-restricted-names\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Never name a parameter `arguments`. This will take precedence over the `arguments` object that is given to every function scope.\n\n    ```javascript\n    // bad\n    function nope(name, options, arguments) {\n      // ...stuff...\n    }\n\n    // good\n    function yup(name, options, args) {\n      // ...stuff...\n    }\n    ```\n\n  \u003ca name=\"es6-rest\"\u003e\u003c/a\u003e\n  - [7.6](#7.6) \u003ca name='7.6'\u003e\u003c/a\u003e Never use `arguments`, opt to use rest syntax `...` instead.\n\n  \u003e Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`.\n\n    ```javascript\n    // bad\n    function concatenateAll() {\n      const args = Array.prototype.slice.call(arguments);\n      return args.join('');\n    }\n\n    // good\n    function concatenateAll(...args) {\n      return args.join('');\n    }\n    ```\n\n  \u003ca name=\"es6-default-parameters\"\u003e\u003c/a\u003e\n  - [7.7](#7.7) \u003ca name='7.7'\u003e\u003c/a\u003e Use default parameter syntax rather than mutating function arguments.\n\n    ```javascript\n    // really bad\n    function handleThings(opts) {\n      // No! We shouldn't mutate function arguments.\n      // Double bad: if opts is falsy it'll be set to an object which may\n      // be what you want but it can introduce subtle bugs.\n      opts = opts || {};\n      // ...\n    }\n\n    // still bad\n    function handleThings(opts) {\n      if (opts === void 0) {\n        opts = {};\n      }\n      // ...\n    }\n\n    // good\n    function handleThings(opts = {}) {\n      // ...\n    }\n    ```\n\n  - [7.8](#7.8) \u003ca name='7.8'\u003e\u003c/a\u003e Avoid side effects with default parameters\n\n  \u003e Why? They are confusing to reason about.\n\n  ```javascript\n  var b = 1;\n  // bad\n  function count(a = b++) {\n    console.log(a);\n  }\n  count();  // 1\n  count();  // 2\n  count(3); // 3\n  count();  // 3\n  ```\n\n  - [7.9](#7.9) \u003ca name='7.9'\u003e\u003c/a\u003e Use argument spreads to interpolate\n    arguments in function calls.\n\n    ```javascript\n    const prefix = [a, b];\n    const suffix = [c, d, e];\n\n    // bad\n    prefix.push.apply(prefix, suffix);\n\n    // good\n    prefix.push(...suffix);\n\n    // bad\n    someFunction.apply(null, prefix.concat(suffix));\n\n    // good\n    someFunction(...prefix, ...suffix);\n    ```\n\n    The exception to this advice is when you really need to use a\n    different, non-`null` value of `this`. Then `.apply` (or `.call`) is\n    probably a better option.\n\n    The same goes for `new` expressions.\n\n    ```javascript\n    class A {\n      constructor(...args) { ... }\n    }\n\n    // really bad\n    const instance = Object.create(A.prototype);\n    A.prototype.constructor.apply(instance, prefix.concat(suffix));\n\n    // good\n    const instance = new A(...prefix, ...suffix);\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Arrow Functions\n\n  - [8.1](#8.1) \u003ca name='8.1'\u003e\u003c/a\u003e When you must use function expressions (as when passing an anonymous function), use arrow function notation.\n\n  \u003e 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.\n\n  \u003e Why not? If you have a fairly complicated function, you might move that logic out into its own function declaration.\n\n    ```javascript\n    // bad\n    [1, 2, 3].map(function (x) {\n      return x * x;\n    });\n\n    // good\n    [1, 2, 3].map((x) =\u003e {\n      return x * x;\n    });\n    ```\n\n  - [8.2](#8.2) \u003ca name='8.2'\u003e\u003c/a\u003e If the function body fits on one line and there is only a single argument, feel free to omit the braces and parentheses, and use the implicit return. Otherwise, add the parentheses, braces, and use a `return` statement.\n\n  \u003e Why? Syntactic sugar. It reads well when multiple functions are chained together.\n\n  \u003e Why not? If you plan on returning an object.\n\n    ```javascript\n    // good\n    [1, 2, 3].map(x =\u003e x * x);\n\n    // good\n    [1, 2, 3].reduce((total, n) =\u003e {\n      return total + n;\n    }, 0);\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Constructors\n\n  - [9.1](#9.1) \u003ca name='9.1'\u003e\u003c/a\u003e Always use `class`. Avoid manipulating `prototype` directly.\n\n  \u003e Why? `class` syntax is more concise and easier to reason about.\n\n    ```javascript\n    // bad\n    function Queue(contents = []) {\n      this._queue = [...contents];\n    }\n    Queue.prototype.pop = function() {\n      const value = this._queue[0];\n      this._queue.splice(0, 1);\n      return value;\n    }\n\n\n    // good\n    class Queue {\n      constructor(contents = []) {\n        this._queue = [...contents];\n      }\n      pop() {\n        const value = this._queue[0];\n        this._queue.splice(0, 1);\n        return value;\n      }\n    }\n    ```\n\n  - [9.2](#9.2) \u003ca name='9.2'\u003e\u003c/a\u003e Use `extends` for inheritance.\n\n  \u003e Why? It is a built-in way to inherit prototype functionality without breaking `instanceof`.\n\n    ```javascript\n    // bad\n    const inherits = require('inherits');\n    function PeekableQueue(contents) {\n      Queue.apply(this, contents);\n    }\n    inherits(PeekableQueue, Queue);\n    PeekableQueue.prototype.peek = function() {\n      return this._queue[0];\n    }\n\n    // good\n    class PeekableQueue extends Queue {\n      peek() {\n        return this._queue[0];\n      }\n    }\n    ```\n\n  - [9.3](#9.3) \u003ca name='9.3'\u003e\u003c/a\u003e Methods can return `this` to help with method chaining.\n\n    ```javascript\n    // bad\n    Jedi.prototype.jump = function() {\n      this.jumping = true;\n      return true;\n    };\n\n    Jedi.prototype.setHeight = function(height) {\n      this.height = height;\n    };\n\n    const luke = new Jedi();\n    luke.jump(); // =\u003e true\n    luke.setHeight(20); // =\u003e undefined\n\n    // good\n    class Jedi {\n      jump() {\n        this.jumping = true;\n        return this;\n      }\n\n      setHeight(height) {\n        this.height = height;\n        return this;\n      }\n    }\n\n    const luke = new Jedi();\n\n    luke.jump()\n      .setHeight(20);\n    ```\n\n\n  - [9.4](#9.4) \u003ca name='9.4'\u003e\u003c/a\u003e It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects.\n\n    ```javascript\n    class Jedi {\n      contructor(options = {}) {\n        this.name = options.name || 'no name';\n      }\n\n      getName() {\n        return this.name;\n      }\n\n      toString() {\n        return `Jedi - ${this.getName()}`;\n      }\n    }\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Modules\n\n  - [10.1](#10.1) \u003ca name='10.1'\u003e\u003c/a\u003e Always use modules (`import`/`export`) over a non-standard module system. You can always transpile to your preferred module system.\n\n  \u003e Why? Modules are the future, let's start using the future now.\n\n    ```javascript\n    // bad\n    const AirbnbStyleGuide = require('./AirbnbStyleGuide');\n    module.exports = AirbnbStyleGuide.es6;\n\n    // ok\n    import AirbnbStyleGuide from './AirbnbStyleGuide';\n    export default AirbnbStyleGuide.es6;\n\n    // best\n    import { es6 } from './AirbnbStyleGuide';\n    export default es6;\n    ```\n\n  - [10.2](#10.2) \u003ca name='10.2'\u003e\u003c/a\u003e Do not use wildcard imports.\n\n  \u003e Why? This makes sure you have a single default export.\n\n    ```javascript\n    // bad\n    import * as AirbnbStyleGuide from './AirbnbStyleGuide';\n\n    // good\n    import AirbnbStyleGuide from './AirbnbStyleGuide';\n    ```\n\n  - [10.3](#10.3) \u003ca name='10.3'\u003e\u003c/a\u003eAnd do not export directly from an import.\n\n  \u003e Why? Although the one-liner is concise, having one clear way to import and one clear way to export makes things consistent.\n\n    ```javascript\n    // bad\n    // filename es6.js\n    export { es6 as default } from './airbnbStyleGuide';\n\n    // good\n    // filename es6.js\n    import { es6 } from './AirbnbStyleGuide';\n    export default es6;\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Iterators and Generators\n\n  - [11.1](#11.1) \u003ca name='11.1'\u003e\u003c/a\u003e Don't use iterators. Prefer JavaScript's higher-order functions like `map()` and `reduce()` instead of loops like `for-of`.\n\n  \u003e Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side-effects.\n\n    ```javascript\n    const numbers = [1, 2, 3, 4, 5];\n\n    // bad\n    let sum = 0;\n    for (let num of numbers) {\n      sum += num;\n    }\n\n    sum === 15;\n\n    // good\n    let sum = 0;\n    numbers.forEach((num) =\u003e sum += num);\n    sum === 15;\n\n    // best (use the functional force)\n    const sum = numbers.reduce((total, num) =\u003e total + num, 0);\n    sum === 15;\n    ```\n\n  - [11.2](#11.2) \u003ca name='11.2'\u003e\u003c/a\u003e Don't use generators for now.\n\n  \u003e Why? They don't transpile well to ES5.\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Properties\n\n  - [12.1](#12.1) \u003ca name='12.1'\u003e\u003c/a\u003e Use dot notation when accessing properties.\n\n    ```javascript\n    const luke = {\n      jedi: true,\n      age: 28,\n    };\n\n    // bad\n    const isJedi = luke['jedi'];\n\n    // good\n    const isJedi = luke.jedi;\n    ```\n\n  - [12.2](#12.2) \u003ca name='12.2'\u003e\u003c/a\u003e Use subscript notation `[]` when accessing properties with a variable.\n\n    ```javascript\n    const luke = {\n      jedi: true,\n      age: 28,\n    };\n\n    function getProp(prop) {\n      return luke[prop];\n    }\n\n    const isJedi = getProp('jedi');\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Variables\n\n  - [13.1](#13.1) \u003ca name='13.1'\u003e\u003c/a\u003e 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.\n\n    ```javascript\n    // bad\n    superPower = new SuperPower();\n\n    // good\n    const superPower = new SuperPower();\n    ```\n\n  - [13.2](#13.2) \u003ca name='13.2'\u003e\u003c/a\u003e Use one `const` declaration per variable.\n\n    \u003e 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.\n\n    ```javascript\n    // bad\n    const items = getItems(),\n        goSportsTeam = true,\n        dragonball = 'z';\n\n    // bad\n    // (compare to above, and try to spot the mistake)\n    const items = getItems(),\n        goSportsTeam = true;\n        dragonball = 'z';\n\n    // good\n    const items = getItems();\n    const goSportsTeam = true;\n    const dragonball = 'z';\n    ```\n\n  - [13.3](#13.3) \u003ca name='13.3'\u003e\u003c/a\u003e Group all your `const`s and then group all your `let`s.\n\n  \u003e Why? This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.\n\n    ```javascript\n    // bad\n    let i, len, dragonball,\n        items = getItems(),\n        goSportsTeam = true;\n\n    // bad\n    let i;\n    const items = getItems();\n    let dragonball;\n    const goSportsTeam = true;\n    let len;\n\n    // good\n    const goSportsTeam = true;\n    const items = getItems();\n    let dragonball;\n    let i;\n    let length;\n    ```\n\n  - [13.4](#13.4) \u003ca name='13.4'\u003e\u003c/a\u003e Assign variables where you need them, but place them in a reasonable place.\n\n  \u003e Why? `let` and `const` are block scoped and not function scoped.\n\n    ```javascript\n    // good\n    function() {\n      test();\n      console.log('doing stuff..');\n\n      //..other stuff..\n\n      const name = getName();\n\n      if (name === 'test') {\n        return false;\n      }\n\n      return name;\n    }\n\n    // bad - unnessary function call\n    function(hasName) {\n      const name = getName();\n\n      if (!hasName) {\n        return false;\n      }\n\n      this.setFirstName(name);\n\n      return true;\n    }\n\n    // good\n    function(hasName) {\n      if (!hasName) {\n        return false;\n      }\n\n      const name = getName();\n      this.setFirstName(name);\n\n      return true;\n    }\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Hoisting\n\n  - [14.1](#14.1) \u003ca name='14.1'\u003e\u003c/a\u003e [14.2](#14.2) \u003ca name='14.2'\u003e\u003c/a\u003e [14.3](#14.3) \u003ca name='14.3'\u003e\u003c/a\u003e [14.4](#14.4) \u003ca name='14.4'\u003e\u003c/a\u003e  Non-rules removed in the Meteor edition.\n\n\n  - For more information refer to [JavaScript Scoping \u0026 Hoisting](http://www.adequatelygood.com/2010/2/JavaS cript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/).\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Comparison Operators \u0026 Equality\n\n  - [15.1](#15.1) \u003ca name='15.1'\u003e\u003c/a\u003e Use `===` and `!==` over `==` and `!=`.\n  - [15.2](#15.2)\u003ca name='15.2'\u003e\u003c/a\u003e/[15.3](#15.3)\u003ca name='15.3'\u003e\u003c/a\u003e/[15.4](#15.4)\u003ca name='15.4'\u003e\u003c/a\u003e\n    Use shortcuts. Note: Conditional statements such as the `if` statement evaluate their expression using coercion with the `ToBoolean` abstract method and always follow the simple rules below. For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll. (15.2, 15.3, and 15.4 merged in Meteor edition):\n\n    + **Objects** evaluate to **true**\n    + **Undefined** evaluates to **false**\n    + **Null** evaluates to **false**\n    + **Booleans** evaluate to **the value of the boolean**\n    + **Numbers** evaluate to **false** if **+0, -0, or NaN**, otherwise **true**\n    + **Strings** evaluate to **false** if an empty string `''`, otherwise **true**\n\n    ```javascript\n    // bad\n    if (name !== '') {\n      // ...stuff...\n    }\n\n    // good\n    if (name) {\n      // ...stuff...\n    }\n\n    // bad\n    if (collection.length \u003e 0) {\n      // ...stuff...\n    }\n\n    // good\n    if (collection.length) {\n      // ...stuff...\n    }\n\n    // note\n    if ([0]) {\n      // true\n      // An array is an object, objects evaluate to true\n    }\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Blocks\n\n  - [16.1](#16.1) \u003ca name='16.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/curly\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use braces with all multi-line blocks.\n\n    ```javascript\n    // bad\n    if (test)\n      return false;\n\n    // good\n    if (test) return false;\n\n    // good\n    if (test) {\n      return false;\n    }\n\n    // bad\n    function() { return false; }\n\n    // good\n    function() {\n      return false;\n    }\n    ```\n\n  - [16.2](#16.2) \u003ca name='16.2'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/brace-style\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    If you're using multi-line blocks with `if` and `else`, put `else` on the same line as your\n    `if` block's closing brace.\n\n    ```javascript\n    // bad\n    if (test) {\n      thing1();\n      thing2();\n    }\n    else {\n      thing3();\n    }\n\n    // good\n    if (test) {\n      thing1();\n      thing2();\n    } else {\n      thing3();\n    }\n    ```\n\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Comments\n\n  - [17.1](#17.1) \u003ca name='17.1'\u003e\u003c/a\u003e Use `/** ... */` for method doc comments. Include a description, specify types and values for all parameters and return values. In the Meteor edition, this rule has been updated to only refer to doc comments.\n\n    ```javascript\n    // bad\n    // make() returns a new element\n    // based on the passed in tag name\n    //\n    // @param {String} tag\n    // @return {Element} element\n    function make(tag) {\n\n      // ...stuff...\n\n      return element;\n    }\n\n    // good\n    /**\n     * make() returns a new element\n     * based on the passed in tag name\n     *\n     * @param {String} tag\n     * @return {Element} element\n     */\n    function make(tag) {\n\n      // ...stuff...\n\n      return element;\n    }\n    ```\n\n  - [17.2](#17.2) \u003ca name='17.2'\u003e\u003c/a\u003e Use `//` for all other comments. Place single line comments on a newline above the subject of the comment. Put an empty line before the comment. Has been updated in Meteor edition to refer to all non-doc comments.\n\n    ```javascript\n    // bad\n    const active = true;  // is current tab\n\n    // good\n    // is current tab\n    const active = true;\n\n    // bad\n    function getType() {\n      console.log('fetching type...');\n      // set the default type to 'no type'\n      const type = this._type || 'no type';\n\n      return type;\n    }\n\n    // good\n    function getType() {\n      console.log('fetching type...');\n\n      // set the default type to 'no type'\n      const type = this._type || 'no type';\n\n      return type;\n    }\n    ```\n\n  - [17.3](#17.3) \u003ca name='17.3'\u003e\u003c/a\u003e 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`.\n\n  - [17.4](#17.4) \u003ca name='17.4'\u003e\u003c/a\u003e Use `// FIXME:` to annotate problems.\n\n    ```javascript\n    class Calculator {\n      constructor() {\n        // FIXME: shouldn't use a global here\n        total = 0;\n      }\n    }\n    ```\n\n  - [17.5](#17.5) \u003ca name='17.5'\u003e\u003c/a\u003e Use `// TODO:` to annotate solutions to problems.\n\n    ```javascript\n    class Calculator {\n      constructor() {\n        // TODO: total should be configurable by an options param\n        this.total = 0;\n      }\n    }\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Whitespace\n\n  - [18.1](#18.1) \u003ca name='18.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/indent\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use soft tabs set to 2 spaces.\n\n    ```javascript\n    // bad\n    function() {\n    ∙∙∙∙const name;\n    }\n\n    // bad\n    function() {\n    ∙const name;\n    }\n\n    // good\n    function() {\n    ∙∙const name;\n    }\n    ```\n\n  - [18.2](#18.2) \u003ca name='18.2'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/space-before-blocks\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Place 1 space before the leading brace.\n\n    ```javascript\n    // bad\n    function test(){\n      console.log('test');\n    }\n\n    // good\n    function test() {\n      console.log('test');\n    }\n\n    // bad\n    dog.set('attr',{\n      age: '1 year',\n      breed: 'Bernese Mountain Dog',\n    });\n\n    // good\n    dog.set('attr', {\n      age: '1 year',\n      breed: 'Bernese Mountain Dog',\n    });\n    ```\n\n  - [18.3](#18.3) \u003ca name='18.3'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/space-before-function-paren\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    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.\n\n    ```javascript\n    // bad\n    if(isJedi) {\n      fight ();\n    }\n\n    // good\n    if (isJedi) {\n      fight();\n    }\n\n    // bad\n    function fight () {\n      console.log ('Swooosh!');\n    }\n\n    // good\n    function fight() {\n      console.log('Swooosh!');\n    }\n    ```\n\n  - [18.4](#18.4) \u003ca name='18.4'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/space-infix-ops\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Set off operators with spaces.\n\n    ```javascript\n    // bad\n    const x=y+5;\n\n    // good\n    const x = y + 5;\n    ```\n\n  - [18.5](#18.5) \u003ca name='18.5'\u003e\u003c/a\u003e End files with a single newline character.\n\n    ```javascript\n    // bad\n    (function(global) {\n      // ...stuff...\n    })(this);\n    ```\n\n    ```javascript\n    // bad\n    (function(global) {\n      // ...stuff...\n    })(this);↵\n    ↵\n    ```\n\n    ```javascript\n    // good\n    (function(global) {\n      // ...stuff...\n    })(this);↵\n    ```\n\n  - [18.5](#18.5) \u003ca name='18.5'\u003e\u003c/a\u003e Use indentation when making long method chains. Use a leading dot, which\n    emphasizes that the line is a method call, not a new statement.\n\n    ```javascript\n    // bad\n    $('#items').find('.selected').highlight().end().find('.open').updateCount();\n\n    // bad\n    $('#items').\n      find('.selected').\n        highlight().\n        end().\n      find('.open').\n        updateCount();\n\n    // good\n    $('#items')\n      .find('.selected')\n        .highlight()\n        .end()\n      .find('.open')\n        .updateCount();\n\n    // bad\n    const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').class('led', true)\n        .attr('width', (radius + margin) * 2).append('svg:g')\n        .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')\n        .call(tron.led);\n\n    // good\n    const leds = stage.selectAll('.led')\n        .data(data)\n      .enter().append('svg:svg')\n        .classed('led', true)\n        .attr('width', (radius + margin) * 2)\n      .append('svg:g')\n        .attr('transform', 'translate(' + (radius + margin) + ',' + (radius + margin) + ')')\n        .call(tron.led);\n    ```\n\n  - [18.6](#18.6) \u003ca name='18.6'\u003e\u003c/a\u003e Leave a blank line after blocks and before the next statement.\n\n    ```javascript\n    // bad\n    if (foo) {\n      return bar;\n    }\n    return baz;\n\n    // good\n    if (foo) {\n      return bar;\n    }\n\n    return baz;\n\n    // bad\n    const obj = {\n      foo() {\n      },\n      bar() {\n      },\n    };\n    return obj;\n\n    // good\n    const obj = {\n      foo() {\n      },\n\n      bar() {\n      },\n    };\n\n    return obj;\n    ```\n\n\n**[⬆ back to top](#table-of-contents)**\n\n## Commas\n\n  - [19.1](#19.1) \u003ca name='19.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/comma-style\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Leading commas: **Nope.**\n\n    ```javascript\n    // bad\n    const story = [\n        once\n      , upon\n      , aTime\n    ];\n\n    // good\n    const story = [\n      once,\n      upon,\n      aTime,\n    ];\n\n    // bad\n    const hero = {\n        firstName: 'Ada'\n      , lastName: 'Lovelace'\n      , birthYear: 1815\n      , superPower: 'computers'\n    };\n\n    // good\n    const hero = {\n      firstName: 'Ada',\n      lastName: 'Lovelace',\n      birthYear: 1815,\n      superPower: 'computers',\n    };\n    ```\n\n  - [19.2](#19.2) \u003ca name='19.2'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/comma-dangle\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Additional trailing comma: **Yup.**\n\n  \u003e 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.\n\n    ```javascript\n    // bad - git diff without trailing comma\n    const hero = {\n         firstName: 'Florence',\n    -    lastName: 'Nightingale'\n    +    lastName: 'Nightingale',\n    +    inventorOf: ['coxcomb graph', 'mordern nursing']\n    }\n\n    // good - git diff with trailing comma\n    const hero = {\n         firstName: 'Florence',\n         lastName: 'Nightingale',\n    +    inventorOf: ['coxcomb chart', 'mordern nursing'],\n    }\n\n    // bad\n    const hero = {\n      firstName: 'Dana',\n      lastName: 'Scully'\n    };\n\n    const heroes = [\n      'Batman',\n      'Superman'\n    ];\n\n    // good\n    const hero = {\n      firstName: 'Dana',\n      lastName: 'Scully',\n    };\n\n    const heroes = [\n      'Batman',\n      'Superman',\n    ];\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Semicolons\n\n  - [20.1](#20.1) \u003ca name='20.1'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/semi\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    **Yup.**\n\n    ```javascript\n    // bad\n    (function() {\n      const name = 'Skywalker'\n      return name\n    })()\n\n    // good\n    (() =\u003e {\n      const name = 'Skywalker';\n      return name;\n    })();\n\n    // good (guards against the function becoming an argument when two files with IIFEs are concatenated)\n    ;(() =\u003e {\n      const name = 'Skywalker';\n      return name;\n    })();\n    ```\n\n    [Read more](http://stackoverflow.com/a/7365214/1712802).\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Type Casting \u0026 Coercion\n\n  - [21.1](#21.1) \u003ca name='21.1'\u003e\u003c/a\u003e Perform type coercion at the beginning of the statement.\n  - [21.2](#21.2) \u003ca name='21.2'\u003e\u003c/a\u003e Strings:\n\n    ```javascript\n    //  =\u003e this.reviewScore = 9;\n\n    // bad\n    const totalScore = this.reviewScore + '';\n\n    // good\n    const totalScore = String(this.reviewScore);\n    ```\n\n  - [21.3](#21.3) \u003ca name='21.3'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/radix\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use `parseInt` to convert strings to numbers, and always with a radix argument.\n\n    ```javascript\n    const inputValue = '4';\n\n    // bad\n    const val = new Number(inputValue);\n\n    // bad\n    const val = inputValue \u003e\u003e 0;\n\n    // bad\n    const val = parseInt(inputValue);\n\n    // good\n    const val = parseInt(inputValue, 10);\n    ```\n\n    Use the `Number` constructor (without `new`) to coerce values that are\n    not strings to numbers, as in `Number(new Date) + 1000`. The unary `+`\n    operator is an acceptable shorthand for `Number(...)`, but only if the\n    expression is not involved in a larger expression, as in `+new Date`.\n\n    Note that the `Number` constructor will return `NaN` if the value\n    cannot be converted to a number, including when the value is\n    undefined. If the output might be `NaN` (likely because the input\n    might be undefined), be sure to test for that possibility after\n    attempting the conversion:\n\n    ```javascript\n    let val = Number(inputValue);\n    if (isNaN(val)) {\n      val = 0;\n    }\n    ```\n\n    Better yet, avoid the possibility of `NaN` through other means, such\n    as providing default values for optional function parameters.\n\n  - [21.4](#21.4) \u003ca name='21.4'\u003e\u003c/a\u003e If you have a very good reason for\n    using some other kind of coercion technique, be it for performance or\n    because you need a very specific output behavior, then you should\n    absolutely leave a comment justifying your choice.\n\n    ```javascript\n    // good\n    /**\n     * parseInt was the reason my code was slow.\n     * Bitshifting the String to coerce it to a\n     * Number made it a lot faster.\n     */\n    const val = inputValue \u003e\u003e 0;\n\n    // good\n    // Truthy inputs must always be coerced to 1, and falsy inputs must\n    // always be cocerced to 0.\n    const zeroOrOne = inputValue ? 1 : 0;\n    ```\n\n  - [21.5](#21.5) \u003ca name='21.5'\u003e\u003c/a\u003e **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:\n\n    ```javascript\n    2147483647 \u003e\u003e 0 //=\u003e 2147483647\n    2147483648 \u003e\u003e 0 //=\u003e -2147483648\n    2147483649 \u003e\u003e 0 //=\u003e -2147483647\n    ```\n\n  - [21.6](#21.6) \u003ca name='21.6'\u003e\u003c/a\u003e Booleans:\n\n    ```javascript\n    const age = 0;\n\n    // bad\n    const hasAge = new Boolean(age);\n\n    // good\n    const hasAge = Boolean(age);\n\n    // good\n    const hasAge = !!age;\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Naming Conventions\n\n  - [22.1](#22.1) \u003ca name='22.1'\u003e\u003c/a\u003e Avoid single letter names. Be descriptive with your naming.\n\n    ```javascript\n    // bad\n    function q() {\n      // ...stuff...\n    }\n\n    // good\n    function query() {\n      // ..stuff..\n    }\n    ```\n\n  - [22.2](#22.2) \u003ca name='22.2'\u003e\u003c/a\u003e \u003ca href=\"http://eslint.org/docs/rules/camelcase\"\u003e\u003cimg src=\"http://eslint.org/img/logo.svg\" height=\"18\" alt=\"linted by eslint\" /\u003e\u003c/a\u003e\n    Use camelCase when naming objects, functions, and instances.\n\n    ```javascript\n    // bad\n    const OBJEcttsssss = {};\n    const this_is_my_object = {};\n    function c() {}\n\n    // good\n    const thisIsMyObject = {};\n    function thisIsMyFunction() {}\n    ```\n\n  - [22.3](#22.3) \u003ca name='22.3'\u003e\u003c/a\u003e Use PascalCase when naming constructors or classes.\n\n    ```javascript\n    // bad\n    function user(options) {\n      this.name = options.name;\n    }\n\n    const bad = new user({\n      name: 'nope',\n    });\n\n    // good\n    class User {\n      constructor(options) {\n        this.name = options.name;\n      }\n    }\n\n    const good = new User({\n      name: 'yup',\n    });\n    ```\n\n  - [22.4](#22.4) \u003ca name='22.4'\u003e\u003c/a\u003e Use a leading underscore `_` when naming private properties.\n\n    ```javascript\n    // bad\n    this.__firstName__ = 'Panda';\n    this.firstName_ = 'Panda';\n\n    // good\n    this._firstName = 'Panda';\n    ```\n\n  - [22.5](#22.5) \u003ca name='22.5'\u003e\u003c/a\u003e Don't save references to `this`. Use arrow functions or Function#bind.\n\n    ```javascript\n    // bad\n    function foo() {\n      const self = this;\n      return function() {\n        console.log(self);\n      };\n    }\n\n    // bad\n    function foo() {\n      const that = this;\n      return function() {\n        console.log(that);\n      };\n    }\n\n    // good\n    function foo() {\n      return () =\u003e {\n        console.log(this);\n      };\n    }\n    ```\n\n  - [22.6](#22.6) \u003ca name='22.6'\u003e\u003c/a\u003e If your file exports a single class, your filename should be exactly the name of the class.\n    ```javascript\n    // file contents\n    export default class CheckBox {\n      // ...\n    }\n\n    // in some other file\n    // bad\n    import CheckBox from './checkBox';\n\n    // bad\n    import CheckBox from './check_box';\n\n    // good\n    import CheckBox from './CheckBox';\n    ```\n\n  - [22.7](#22.7) \u003ca name='22.7'\u003e\u003c/a\u003e Use camelCase when you export-default a function. Your filename should be identical to your function's name.\n\n    ```javascript\n    function makeStyleGuide() {\n    }\n\n    export default makeStyleGuide;\n    ```\n\n  - [22.8](#22.8) \u003ca name='22.8'\u003e\u003c/a\u003e Use PascalCase when you export a singleton / function library / bare object.\n\n    ```javascript\n    const AirbnbStyleGuide = {\n      es6: {\n      }\n    };\n\n    export default AirbnbStyleGuide;\n    ```\n\n  - [22.9](#22.9) \u003ca name='22.9'\u003e\u003c/a\u003e Prefer `export`ing declarations\n    where they are declared, rather than at the end of the file:\n\n    ```javascript\n    // bad\n    function createUser(name) { ... }\n    function getOrCreateUser(name) { ... }\n    // ... rest of file ...\n    export {\n      createUser,\n      getOrCreateUser,\n    }\n\n    // good\n    export function createUser(name) { ... }\n    export function getOrCreateUser(name) { ... }\n    // ... rest of file ...\n    ```\n\n    This style ensures that the set of `export`s remains up-to-date as\n    declarations are added or removed.\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Accessors\n\n  - [23.1](#23.1) \u003ca name='23.1'\u003e\u003c/a\u003e Accessor functions for properties are not required.\n  - [23.2](#23.2) \u003ca name='23.2'\u003e\u003c/a\u003e If you do make accessor functions use getVal() and setVal('hello').\n\n    ```javascript\n    // bad\n    dragon.age();\n\n    // good\n    dragon.getAge();\n\n    // bad\n    dragon.age(25);\n\n    // good\n    dragon.setAge(25);\n    ```\n\n  - [23.3](#23.3) \u003ca name='23.3'\u003e\u003c/a\u003e If the property is a boolean, use isVal() or hasVal().\n\n    ```javascript\n    // bad\n    if (!dragon.age()) {\n      return false;\n    }\n\n    // good\n    if (!dragon.hasAge()) {\n      return false;\n    }\n    ```\n\n  - [23.4](#23.4) \u003ca name='23.4'\u003e\u003c/a\u003e It's okay to create get() and set() functions, but be consistent.\n\n    ```javascript\n    class Jedi {\n      constructor(options = {}) {\n        const lightsaber = options.lightsaber || 'blue';\n        this.set('lightsaber', lightsaber);\n      }\n\n      set(key, val) {\n        this[key] = val;\n      }\n\n      get(key) {\n        return this[key];\n      }\n    }\n    ```\n\n  - [23.5](#23.5) \u003ca name='23.5'\u003e\u003c/a\u003e Strongly prefer accessor methods to\n    defining ES5 getter and setter properties:\n\n    ```javascript\n    class Jedi {\n      constructor({ lightsaber = blue }) {\n        this._lightsaber = lightsaber;\n      }\n\n      // bad; use a normal getter method instead\n      get lightsaber() {\n        return this._lightsaber;\n      }\n\n      // bad; use a normal setter method instead\n      set lightsaber(newLightSaber) {\n        return this._lightsaber = newLightSaber;\n      }\n    }\n    ```\n\n    Not only is this style rarely more readable than the method\n    equivalent, performance can suffer dramatically when code relies on\n    specially-defined properties rather than just using normal properties.\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Events\n\n  - [24.1](#24.1) \u003ca name='24.1'\u003e\u003c/a\u003e 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:\n\n    ```javascript\n    // bad\n    $(this).trigger('listingUpdated', listing.id);\n\n    ...\n\n    $(this).on('listingUpdated', function(e, listingId) {\n      // do something with listingId\n    });\n    ```\n\n    prefer:\n\n    ```javascript\n    // good\n    $(this).trigger('listingUpdated', { listingId : listing.id });\n\n    ...\n\n    $(this).on('listingUpdated', function(e, data) {\n      // do something with data.listingId\n    });\n    ```\n\n  **[⬆ back to top](#table-of-contents)**\n\n\n## jQuery\n\n  - [25.1](#25.1) \u003ca name='25.1'\u003e\u003c/a\u003e Prefix jQuery object variables with a `$`.\n\n    ```javascript\n    // bad\n    const sidebar = $('.sidebar');\n\n    // good\n    const $sidebar = $('.sidebar');\n    ```\n\n  - [25.2](#25.2) \u003ca name='25.2'\u003e\u003c/a\u003e Cache jQuery lookups.\n\n    ```javascript\n    // bad\n    function setSidebar() {\n      $('.sidebar').hide();\n\n      // ...stuff...\n\n      $('.sidebar').css({\n        'background-color': 'pink'\n      });\n    }\n\n    // good\n    function setSidebar() {\n      const $sidebar = $('.sidebar');\n      $sidebar.hide();\n\n      // ...stuff...\n\n      $sidebar.css({\n        'background-color': 'pink'\n      });\n    }\n    ```\n\n  - [25.3](#25.3) \u003ca name='25.3'\u003e\u003c/a\u003e For DOM queries use Cascading `$('.sidebar ul')` or parent \u003e child `$('.sidebar \u003e ul')`. [jsPerf](http://jsperf.com/jquery-find-vs-context-sel/16)\n  - [25.4](#25.4) \u003ca name='25.4'\u003e\u003c/a\u003e Use `find` with scoped jQuery object queries.\n\n    ```javascript\n    // bad\n    $('ul', '.sidebar').hide();\n\n    // bad\n    $('.sidebar').find('ul').hide();\n\n    // good\n    $('.sidebar ul').hide();\n\n    // good\n    $('.sidebar \u003e ul').hide();\n\n    // good\n    $sidebar.find('ul').hide();\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## ECMAScript 5 Compatibility\n\n  - [26.1](#26.1) \u003ca name='26.1'\u003e\u003c/a\u003e Refer to [Kangax](https://twitter.com/kangax/)'s ES5 [compatibility table](http://kangax.github.com/es5-compat-table/).\n\n**[⬆ back to top](#table-of-contents)**\n\n## ECMAScript 6 Styles\n\n  - [27.1](#27.1) \u003ca name='27.1'\u003e\u003c/a\u003e This is a collection of links to the various es6 features.\n\n1. [Arrow Functions](#arrow-functions)\n1. [Classes](#constructors)\n1. [Object Shorthand](#es6-object-shorthand)\n1. [Object Concise](#es6-object-concise)\n1. [Object Computed Properties](#es6-computed-properties)\n1. [Template Strings](#es6-template-literals)\n1. [Destructuring](#destructuring)\n1. [Default Parameters](#es6-default-parameters)\n1. [Rest](#es6-rest)\n1. [Array Spreads](#es6-array-spreads)\n1. [Let and Const](#references)\n1. [Iterators and Generators](#iterators-and-generators)\n1. [Modules](#modules)\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Contributors\n\n  - [View Contributors](https://github.com/airbnb/javascript/graphs/contributors)\n\n\n## License\n\n(The MIT License)\n\nCopyright (c) 2014 Airbnb\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n'Software'), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.\nIN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY\nCLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,\nTORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE\nSOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n\n**[⬆ back to top](#table-of-contents)**\n\n# };\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeteor%2Fjavascript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmeteor%2Fjavascript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmeteor%2Fjavascript/lists"}