{"id":20419395,"url":"https://github.com/risingstack/node-style-guide","last_synced_at":"2026-01-25T06:44:57.405Z","repository":{"id":17974572,"uuid":"20974665","full_name":"RisingStack/node-style-guide","owner":"RisingStack","description":"A mostly reasonable approach to JavaScript - how we write Node.js at RisingStack","archived":false,"fork":false,"pushed_at":"2019-10-17T20:19:43.000Z","size":58,"stargazers_count":990,"open_issues_count":11,"forks_count":141,"subscribers_count":73,"default_branch":"master","last_synced_at":"2025-01-15T14:17:07.101Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/RisingStack.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":"2014-06-18T19:10:49.000Z","updated_at":"2024-12-27T12:06:43.000Z","dependencies_parsed_at":"2022-07-13T05:30:33.163Z","dependency_job_id":null,"html_url":"https://github.com/RisingStack/node-style-guide","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fnode-style-guide","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fnode-style-guide/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fnode-style-guide/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/RisingStack%2Fnode-style-guide/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/RisingStack","download_url":"https://codeload.github.com/RisingStack/node-style-guide/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241961346,"owners_count":20049451,"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","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-11-15T06:36:47.839Z","updated_at":"2026-01-25T06:44:57.376Z","avatar_url":"https://github.com/RisingStack.png","language":null,"readme":"### Depraction notice\n\nWe are moving / moved our projects to use [Standard](https://github.com/feross/standard) - check it out!\n\n# [RisingStack](http://risingstack.com) Node.js Style Guide() {\n\n### Most of the content is taken from the [Airbnb styleguide](https://github.com/airbnb/javascript)\n\nHeavily inspired by them as well:\n- @caolan's [Node.js styleguide](http://caolanmcmahon.com/posts/nodejs_style_and_structure)\n- @felixge's [Node.js styleguide](https://github.com/felixge/node-style-guide)\n\n## Table of Contents\n\n  1. [Types](#types)\n  1. [Objects](#objects)\n  1. [Arrays](#arrays)\n  1. [Strings](#strings)\n  1. [Functions](#functions)\n  1. [Properties](#properties)\n  1. [Variables](#variables)\n  1. [Requires](#requires)\n  1. [Callbacks](#callbacks)\n  1. [Try-catch](#try-catch)\n  1. [Hoisting](#hoisting)\n  1. [Conditional Expressions \u0026 Equality](#conditional-expressions--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. [Constructors](#constructors)\n  1. [Contributors](#contributors)\n  1. [License](#license)\n\n## Types\n\n  - **Primitives**: When you access a primitive type you work directly on its value\n\n    + `string`\n    + `number`\n    + `boolean`\n    + `null`\n    + `undefined`\n\n    ```javascript\n    var foo = 1;\n    var bar = foo;\n\n    bar = 9;\n\n    console.log(foo, bar); // =\u003e 1, 9\n    ```\n  - **Complex**: When you access a complex type you work on a reference to its value\n\n    + `object`\n    + `array`\n    + `function`\n\n    ```javascript\n    var foo = [1, 2];\n    var bar = foo;\n\n    bar[0] = 9;\n\n    console.log(foo[0], bar[0]); // =\u003e 9, 9\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Objects\n\n  - Use the literal syntax for object creation.\n\n    ```javascript\n    // bad\n    var item = new Object();\n\n    // good\n    var item = {};\n    ```\n\n  - Use readable synonyms in place of reserved words.\n\n    ```javascript\n    // bad\n    var superman = {\n      class: 'alien'\n    };\n\n    // bad\n    var superman = {\n      klass: 'alien'\n    };\n\n    // good\n    var superman = {\n      type: 'alien'\n    };\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Arrays\n\n  - Use the literal syntax for array creation\n\n    ```javascript\n    // bad\n    var items = new Array();\n\n    // good\n    var items = [];\n    ```\n\n  - If you don't know array length use Array#push.\n\n    ```javascript\n    var someStack = [];\n\n\n    // bad\n    someStack[someStack.length] = 'abracadabra';\n\n    // good\n    someStack.push('abracadabra');\n    ```\n\n  - When you need to copy an array use Array#slice. [jsPerf](http://jsperf.com/converting-arguments-to-an-array/7)\n\n    ```javascript\n    var len = items.length;\n    var itemsCopy = [];\n    var i;\n\n    // bad\n    for (i = 0; i \u003c len; i++) {\n      itemsCopy[i] = items[i];\n    }\n\n    // good\n    itemsCopy = items.slice();\n    ```\n\n  - To convert an array-like object to an array, use Array#slice.\n\n    ```javascript\n    function trigger() {\n      var args = Array.prototype.slice.call(arguments);\n      ...\n    }\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Strings\n\n  - Use single quotes `''` for strings\n\n    ```javascript\n    // bad\n    var name = \"Bob Parr\";\n\n    // good\n    var name = 'Bob Parr';\n\n    // bad\n    var fullName = \"Bob \" + this.lastName;\n\n    // good\n    var fullName = 'Bob ' + this.lastName;\n    ```\n\n  - Strings longer than 80 characters should be written across multiple lines using string concatenation.\n  - 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    var 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    var 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    var 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  - When programmatically building up a string, use Array#join instead of string concatenation.\n\n    ```javascript\n    var items;\n    var messages;\n    var length;\n    var i;\n\n    messages = [{\n      state: 'success',\n      message: 'This one worked.'\n    }, {\n      state: 'success',\n      message: 'This one worked as well.'\n    }, {\n      state: 'error',\n      message: 'This one did not work.'\n    }];\n\n    length = messages.length;\n\n    // bad\n    function inbox(messages) {\n      items = '\u003cul\u003e';\n\n      for (i = 0; i \u003c length; i++) {\n        items += '\u003cli\u003e' + messages[i].message + '\u003c/li\u003e';\n      }\n\n      return items + '\u003c/ul\u003e';\n    }\n\n    // good\n    function inbox(messages) {\n      items = [];\n\n      for (i = 0; i \u003c length; i++) {\n        items[i] = messages[i].message;\n      }\n\n      return '\u003cul\u003e\u003cli\u003e' + items.join('\u003c/li\u003e\u003cli\u003e') + '\u003c/li\u003e\u003c/ul\u003e';\n    }\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Functions\n\n  - Function expressions:\n\n    ```javascript\n    // anonymous function expression\n    var anonymous = function() {\n      return true;\n    };\n\n    // named function expression\n    var named = function named() {\n      return true;\n    };\n\n    // immediately-invoked function expression (IIFE)\n    (function() {\n      console.log('Welcome to the Internet. Please follow me.');\n    })();\n    ```\n\n  - Never declare a function in a non-function block (if, while, etc). Assign the function to a variable instead.\n\n    ```javascript\n    // bad\n    if (currentUser) {\n      function test() {\n        console.log('Nope.');\n      }\n    }\n\n    // good\n    var test;\n    if (currentUser) {\n      test = function test() {\n        console.log('Yup.');\n      };\n    }\n    ```\n\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**[⬆ back to top](#table-of-contents)**\n\n\n\n## Properties\n\n  - Use dot notation when accessing properties.\n\n    ```javascript\n    var luke = {\n      jedi: true,\n      age: 28\n    };\n\n    // bad\n    var isJedi = luke['jedi'];\n\n    // good\n    var isJedi = luke.jedi;\n    ```\n\n  - Use subscript notation `[]` when accessing properties with a variable.\n\n    ```javascript\n    var luke = {\n      jedi: true,\n      age: 28\n    };\n\n    function getProp(prop) {\n      return luke[prop];\n    }\n\n    var isJedi = getProp('jedi');\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Variables\n\n  - Always use `var` 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    var superPower = new SuperPower();\n    ```\n\n  - Declare each variable on a newline, with a `var` before each of them.\n\n    ```javascript\n    // bad\n     var items = getItems(),\n          goSportsTeam = true,\n          dragonball = 'z';\n\n    // good\n     var items = getItems();\n     var goSportsTeam = true;\n     var dragonball = 'z';\n    ```\n\n  - Declare unassigned variables last. 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    var i;\n    var items = getItems();\n    var dragonball;\n    var goSportsTeam = true;\n    var len;\n\n    // good\n    var items = getItems();\n    var goSportsTeam = true;\n    var dragonball;\n    var length;\n    var i;\n    ```\n\n  - Avoid redundant variable names, use `Object` instead.\n\n    ```javascript\n\n    // bad\n    var kaleidoscopeName = '..';\n    var kaleidoscopeLens = [];\n    var kaleidoscopeColors = [];\n\n    // good\n    var kaleidoscope = {\n      name: '..',\n      lens: [],\n      colors: []\n    };\n    ```\n\n  - Assign variables at the top of their scope. This helps avoid issues with variable declaration and assignment hoisting related issues.\n\n    ```javascript\n    // bad\n    function() {\n      test();\n      console.log('doing stuff..');\n\n      //..other stuff..\n\n      var name = getName();\n\n      if (name === 'test') {\n        return false;\n      }\n\n      return name;\n    }\n\n    // good\n    function() {\n      var name = getName();\n\n      test();\n      console.log('doing stuff..');\n\n      //..other stuff..\n\n      if (name === 'test') {\n        return false;\n      }\n\n      return name;\n    }\n\n    // bad\n    function() {\n      var name = getName();\n\n      if (!arguments.length) {\n        return false;\n      }\n\n      return true;\n    }\n\n    // good\n    function() {\n      if (!arguments.length) {\n        return false;\n      }\n\n      var name = getName();\n\n      return true;\n    }\n    ```\n\n## Requires\n\n  - Organize your node requires in the following order:\n      - core modules\n      - npm modules\n      - others\n\n    ```javascript\n    // bad\n    var Car = require('./models/Car');\n    var async = require('async');\n    var http = require('http');\n\n    // good\n    var http = require('http');\n    var fs = require('fs');\n\n    var async = require('async');\n    var mongoose = require('mongoose');\n\n    var Car = require('./models/Car');\n    ```\n\n  - Do not use the `.js` when requiring modules\n\n  ```javascript\n    // bad\n    var Batmobil = require('./models/Car.js');\n\n    // good\n    var Batmobil = require('./models/Car');\n\n  ```\n\n\n**[⬆ back to top](#table-of-contents)**\n\n## Callbacks\n\n  - Always check for errors in callbacks\n\n  ```javascript\n  //bad\n  database.get('pokemons', function(err, pokemons) {\n    console.log(pokemons);\n  });\n\n  //good\n  database.get('drabonballs', function(err, drabonballs) {\n    if (err) {\n      // handle the error somehow, maybe return with a callback\n      return console.log(err);\n    }\n    console.log(drabonballs);\n  });\n  ```\n\n  - Return on callbacks\n\n  ```javascript\n  //bad\n  database.get('drabonballs', function(err, drabonballs) {\n    if (err) {\n      // if not return here\n      console.log(err);\n    }\n    // this line will be executed as well\n    console.log(drabonballs);\n  });\n\n  //good\n  database.get('drabonballs', function(err, drabonballs) {\n    if (err) {\n      // handle the error somehow, maybe return with a callback\n      return console.log(err);\n    }\n    console.log(drabonballs);\n  });\n  ```\n\n  - Use descriptive arguments in your callback when it is an \"interface\" for others. It makes your code readable.\n\n  ```javascript\n  // bad\n  function getAnimals(done) {\n    Animal.get(done);\n  }\n\n  // good\n  function getAnimals(done) {\n    Animal.get(function(err, animals) {\n      if(err) {\n        return done(err);\n      }\n\n      return done(null, {\n        dogs: animals.dogs,\n        cats: animals.cats\n      })\n    });\n  }\n  ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Try catch\n\n- Only throw in synchronous functions\n\n  Try-catch blocks cannot be used to wrap async code. They will bubble up to the top, and bring\n  down the entire process.\n\n  ```javascript\n  //bad\n  function readPackageJson (callback) {\n    fs.readFile('package.json', function(err, file) {\n      if (err) {\n        throw err;\n      }\n      ...\n    });\n  }\n  //good\n  function readPackageJson (callback) {\n    fs.readFile('package.json', function(err, file) {\n      if (err) {\n        return  callback(err);\n      }\n      ...\n    });\n  }\n  ```\n\n- Catch errors in sync calls\n\n  ```javascript\n  //bad\n  var data = JSON.parse(jsonAsAString);\n\n  //good\n  var data;\n  try {\n    data = JSON.parse(jsonAsAString);\n  } catch (e) {\n    //handle error - hopefully not with a console.log ;)\n    console.log(e);\n  }\n  ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Hoisting\n\n  - Variable declarations get hoisted to the top of their scope, their assignment does not.\n\n    ```javascript\n    // we know this wouldn't work (assuming there\n    // is no notDefined global variable)\n    function example() {\n      console.log(notDefined); // =\u003e throws a ReferenceError\n    }\n\n    // creating a variable declaration after you\n    // reference the variable will work due to\n    // variable hoisting. Note: the assignment\n    // value of `true` is not hoisted.\n    function example() {\n      console.log(declaredButNotAssigned); // =\u003e undefined\n      var declaredButNotAssigned = true;\n    }\n\n    // The interpreter is hoisting the variable\n    // declaration to the top of the scope.\n    // Which means our example could be rewritten as:\n    function example() {\n      var declaredButNotAssigned;\n      console.log(declaredButNotAssigned); // =\u003e undefined\n      declaredButNotAssigned = true;\n    }\n    ```\n\n  - Anonymous function expressions hoist their variable declaration, but not the function assignment.\n\n    ```javascript\n    function example() {\n      console.log(anonymous); // =\u003e undefined\n\n      anonymous(); // =\u003e TypeError anonymous is not a function\n\n      var anonymous = function() {\n        console.log('anonymous function expression');\n      };\n    }\n    ```\n\n  - Named function expressions hoist the variable declaration, but neither the function declaration nor the function body.\n\n    ```javascript\n    function example() {\n      console.log(named); // =\u003e undefined\n\n      named(); // =\u003e TypeError named is not a function\n\n      superPower(); // =\u003e ReferenceError superPower is not defined\n\n      var named = function superPower() {\n        console.log('Flying');\n      };\n    }\n\n    // the same is true when the function name\n    // is the same as the variable name.\n    function example() {\n      console.log(named); // =\u003e undefined\n\n      named(); // =\u003e TypeError named is not a function\n\n      var named = function named() {\n        console.log('named');\n      }\n    }\n    ```\n\n  - Function declarations hoist their name and the function body.\n\n    ```javascript\n    function example() {\n      superPower(); // =\u003e Flying\n\n      function superPower() {\n        console.log('Flying');\n      }\n    }\n    ```\n\n  - For more information refer to [JavaScript Scoping \u0026 Hoisting](http://www.adequatelygood.com/2010/2/JavaScript-Scoping-and-Hoisting) by [Ben Cherry](http://www.adequatelygood.com/)\n\n**[⬆ back to top](#table-of-contents)**\n\n\n\n## Conditional Expressions \u0026 Equality\n\n  - Use `===` and `!==` over `==` and `!=`.\n  - Conditional expressions are evaluated using coercion with the `ToBoolean` method and always follow these simple rules:\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    if ([0]) {\n      // true\n      // An array is an object, objects evaluate to true\n    }\n    ```\n\n  - Use shortcuts.\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\n  - For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Blocks\n\n  - Use braces with all multi-line blocks.\n\n    ```javascript\n    // bad\n    if (test)\n      return false;\n\n    // bad\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**[⬆ back to top](#table-of-contents)**\n\n\n## Comments\n\n  - Use `/** ... */` for multiline comments. Include a description, specify types and values for all parameters and return values.\n\n    ```javascript\n    // bad\n    // make() returns a new element\n    // based on the passed in tag name\n    //\n    // @param \u003cString\u003e tag\n    // @return \u003cElement\u003e 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 \u003cString\u003e tag\n     * @return \u003cElement\u003e element\n     */\n    function make(tag) {\n\n      // ...stuff...\n\n      return element;\n    }\n    ```\n\n  - 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.\n\n    ```javascript\n    // bad\n    var active = true;  // is current tab\n\n    // good\n    // is current tab\n    var active = true;\n\n    // bad\n    function getType() {\n      console.log('fetching type...');\n      // set the default type to 'no type'\n      var 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      var type = this._type || 'no type';\n\n      return type;\n    }\n    ```\n\n  - 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  - Use `// FIXME:` to annotate problems\n\n    ```javascript\n    function Calculator() {\n\n      // FIXME: shouldn't use a global here\n      total = 0;\n\n      return this;\n    }\n    ```\n\n  - Use `// TODO:` to annotate solutions to problems\n\n    ```javascript\n    function Calculator() {\n\n      // TODO: total should be configurable by an options param\n      this.total = 0;\n\n      return this;\n    }\n  ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Whitespace\n\n  - Use soft tabs set to 2 spaces\n\n    ```javascript\n    // bad\n    function() {\n    ∙∙∙∙var name;\n    }\n\n    // bad\n    function() {\n    ∙var name;\n    }\n\n    // good\n    function() {\n    ∙∙var name;\n    }\n    ```\n\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  - Set off operators with spaces.\n\n    ```javascript\n    // bad\n    var x=y+5;\n\n    // good\n    var x = y + 5;\n    ```\n\n  - 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  - Use indentation when making long method chains.\n\n    ```javascript\n    // bad\n    $('#items').find('.selected').highlight().end().find('.open').updateCount();\n\n    // good\n    $('#items')\n      .find('.selected')\n        .highlight()\n        .end()\n      .find('.open')\n        .updateCount();\n\n    // bad\n    var 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    var leds = stage.selectAll('.led')\n        .data(data)\n      .enter().append('svg:svg')\n        .class('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**[⬆ back to top](#table-of-contents)**\n\n## Commas\n\n  - Leading commas: **Nope.**\n\n    ```javascript\n    // bad\n    var hero = {\n        firstName: 'Bob'\n      , lastName: 'Parr'\n      , heroName: 'Mr. Incredible'\n      , superPower: 'strength'\n    };\n\n    // good\n    var hero = {\n      firstName: 'Bob',\n      lastName: 'Parr',\n      heroName: 'Mr. Incredible',\n      superPower: 'strength'\n    };\n    ```\n\n  - Additional trailing comma: **Nope.** This can cause problems with IE6/7 and IE9 if it's in quirksmode. Also, in some implementations of ES3 would add length to an array if it had an additional trailing comma. This was clarified in ES5 ([source](http://es5.github.io/#D)):\n\n  \u003e Edition 5 clarifies the fact that a trailing comma at the end of an ArrayInitialiser does not add to the length of the array. This is not a semantic change from Edition 3 but some implementations may have previously misinterpreted this.\n\n    ```javascript\n    // bad\n    var hero = {\n      firstName: 'Kevin',\n      lastName: 'Flynn',\n    };\n\n    var heroes = [\n      'Batman',\n      'Superman',\n    ];\n\n    // good\n    var hero = {\n      firstName: 'Kevin',\n      lastName: 'Flynn'\n    };\n\n    var heroes = [\n      'Batman',\n      'Superman'\n    ];\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Semicolons\n\n  - **Yup.**\n\n    ```javascript\n    // bad\n    (function() {\n      var name = 'Skywalker'\n      return name\n    })()\n\n    // good\n    (function() {\n      var name = 'Skywalker';\n      return name;\n    })();\n\n    // good\n    ;(function() {\n      var name = 'Skywalker';\n      return name;\n    })();\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Type Casting \u0026 Coercion\n\n  - Perform type coercion at the beginning of the statement.\n  - Strings:\n\n    ```javascript\n    //  =\u003e this.reviewScore = 9;\n\n    // bad\n    var totalScore = this.reviewScore + '';\n\n    // good\n    var totalScore = '' + this.reviewScore;\n\n    // bad\n    var totalScore = '' + this.reviewScore + ' total score';\n\n    // good\n    var totalScore = this.reviewScore + ' total score';\n    ```\n\n  - Use `parseInt` for Numbers and always with a radix for type casting.\n\n    ```javascript\n    var inputValue = '4';\n\n    // bad\n    var val = new Number(inputValue);\n\n    // bad\n    var val = +inputValue;\n\n    // bad\n    var val = inputValue \u003e\u003e 0;\n\n    // bad\n    var val = parseInt(inputValue);\n\n    // good\n    var val = Number(inputValue);\n\n    // good\n    var val = parseInt(inputValue, 10);\n    ```\n\n  - 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.\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    var val = inputValue \u003e\u003e 0;\n    ```\n\n  - **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  - Booleans:\n\n    ```javascript\n    var age = 0;\n\n    // bad\n    var hasAge = new Boolean(age);\n\n    // good\n    var hasAge = Boolean(age);\n\n    // good\n    var hasAge = !!age;\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Naming Conventions\n\n  - 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  - Use camelCase when naming objects, functions, and instances\n\n    ```javascript\n    // bad\n    var OBJEcttsssss = {};\n    var this_is_my_object = {};\n    function c() {}\n    var u = new user({\n      name: 'Bob Parr'\n    });\n\n    // good\n    var thisIsMyObject = {};\n    function thisIsMyFunction() {}\n    var user = new User({\n      name: 'Bob Parr'\n    });\n    ```\n\n  - Use PascalCase when naming constructors or classes\n\n    ```javascript\n    // bad\n    function user(options) {\n      this.name = options.name;\n    }\n\n    var bad = new user({\n      name: 'nope'\n    });\n\n    // good\n    function User(options) {\n      this.name = options.name;\n    }\n\n    var good = new User({\n      name: 'yup'\n    });\n    ```\n\n  - 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  - When saving a reference to `this` use `_this`.\n\n    ```javascript\n    // bad\n    function() {\n      var self = this;\n      return function() {\n        console.log(self);\n      };\n    }\n\n    // bad\n    function() {\n      var that = this;\n      return function() {\n        console.log(that);\n      };\n    }\n\n    // good\n    function() {\n      var _this = this;\n      return function() {\n        console.log(_this);\n      };\n    }\n    ```\n\n  - Name your functions. This is helpful for stack traces.\n\n    ```javascript\n    // bad\n    var log = function(msg) {\n      console.log(msg);\n    };\n\n    // good\n    var log = function log(msg) {\n      console.log(msg);\n    };\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n\n## Accessors\n\n  - Accessor functions for properties are not required\n  - 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  - 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  - It's okay to create get() and set() functions, but be consistent.\n\n    ```javascript\n    function Jedi(options) {\n      options || (options = {});\n      var lightsaber = options.lightsaber || 'blue';\n      this.set('lightsaber', lightsaber);\n    }\n\n    Jedi.prototype.set = function(key, val) {\n      this[key] = val;\n    };\n\n    Jedi.prototype.get = function(key) {\n      return this[key];\n    };\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n## Constructors\n\n  - Assign methods to the prototype object, instead of overwriting the prototype with a new object. Overwriting the prototype makes inheritance impossible: by resetting the prototype you'll overwrite the base!\n\n    ```javascript\n    function Jedi() {\n      console.log('new jedi');\n    }\n\n    // bad\n    Jedi.prototype = {\n      fight: function fight() {\n        console.log('fighting');\n      },\n\n      block: function block() {\n        console.log('blocking');\n      }\n    };\n\n    // good\n    Jedi.prototype.fight = function fight() {\n      console.log('fighting');\n    };\n\n    Jedi.prototype.block = function block() {\n      console.log('blocking');\n    };\n    ```\n\n  - 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    var luke = new Jedi();\n    luke.jump(); // =\u003e true\n    luke.setHeight(20) // =\u003e undefined\n\n    // good\n    Jedi.prototype.jump = function() {\n      this.jumping = true;\n      return this;\n    };\n\n    Jedi.prototype.setHeight = function(height) {\n      this.height = height;\n      return this;\n    };\n\n    var luke = new Jedi();\n\n    luke.jump()\n      .setHeight(20);\n    ```\n\n\n  - It's okay to write a custom toString() method, just make sure it works successfully and causes no side effects.\n\n    ```javascript\n    function Jedi(options) {\n      options || (options = {});\n      this.name = options.name || 'no name';\n    }\n\n    Jedi.prototype.getName = function getName() {\n      return this.name;\n    };\n\n    Jedi.prototype.toString = function toString() {\n      return 'Jedi - ' + this.getName();\n    };\n    ```\n\n**[⬆ back to top](#table-of-contents)**\n\n**Books**\n\n  - [JavaScript: The Good Parts](http://www.amazon.com/JavaScript-Good-Parts-Douglas-Crockford/dp/0596517742) - Douglas Crockford\n  - [JavaScript Patterns](http://www.amazon.com/JavaScript-Patterns-Stoyan-Stefanov/dp/0596806752) - Stoyan Stefanov\n  - [Pro JavaScript Design Patterns](http://www.amazon.com/JavaScript-Design-Patterns-Recipes-Problem-Solution/dp/159059908X)  - Ross Harmes and Dustin Diaz\n  - [High Performance Web Sites: Essential Knowledge for Front-End Engineers](http://www.amazon.com/High-Performance-Web-Sites-Essential/dp/0596529309) - Steve Souders\n  - [Maintainable JavaScript](http://www.amazon.com/Maintainable-JavaScript-Nicholas-C-Zakas/dp/1449327680) - Nicholas C. Zakas\n  - [JavaScript Web Applications](http://www.amazon.com/JavaScript-Web-Applications-Alex-MacCaw/dp/144930351X) - Alex MacCaw\n  - [Pro JavaScript Techniques](http://www.amazon.com/Pro-JavaScript-Techniques-John-Resig/dp/1590597273) - John Resig\n  - [Smashing Node.js: JavaScript Everywhere](http://www.amazon.com/Smashing-Node-js-JavaScript-Everywhere-Magazine/dp/1119962595) - Guillermo Rauch\n  - [Secrets of the JavaScript Ninja](http://www.amazon.com/Secrets-JavaScript-Ninja-John-Resig/dp/193398869X) - John Resig and Bear Bibeault\n  - [Human JavaScript](http://humanjavascript.com/) - Henrik Joreteg\n  - [Superhero.js](http://superherojs.com/) - Kim Joar Bekkelund, Mads Mobæk, \u0026 Olav Bjorkoy\n  - [JSBooks](http://jsbooks.revolunet.com/)\n  - [Third Party JavaScript](http://manning.com/vinegar/) - Ben Vinegar and Anton Kovalyov\n\n**Blogs**\n\n  - [DailyJS](http://dailyjs.com/)\n  - [JavaScript Weekly](http://javascriptweekly.com/)\n  - [JavaScript, JavaScript...](http://javascriptweblog.wordpress.com/)\n  - [Bocoup Weblog](http://weblog.bocoup.com/)\n  - [Adequately Good](http://www.adequatelygood.com/)\n  - [NCZOnline](http://www.nczonline.net/)\n  - [Perfection Kills](http://perfectionkills.com/)\n  - [Ben Alman](http://benalman.com/)\n  - [Dmitry Baranovskiy](http://dmitry.baranovskiy.com/)\n  - [Dustin Diaz](http://dustindiaz.com/)\n  - [nettuts](http://net.tutsplus.com/?s=javascript)\n\n**[⬆ back to top](#table-of-contents)**\n\n## The JavaScript Style Guide Guide\n\n  - [Reference](https://github.com/airbnb/javascript/wiki/The-JavaScript-Style-Guide-Guide)\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 RisingStack\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","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frisingstack%2Fnode-style-guide","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frisingstack%2Fnode-style-guide","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frisingstack%2Fnode-style-guide/lists"}