Skip to content

Instantly share code, notes, and snippets.

@pkyeck
Forked from sindresorhus/codestyle.md
Created December 13, 2012 10:22
Show Gist options
  • Save pkyeck/4275522 to your computer and use it in GitHub Desktop.
Save pkyeck/4275522 to your computer and use it in GitHub Desktop.

Revisions

  1. pkyeck revised this gist Dec 13, 2012. 1 changed file with 14 additions and 13 deletions.
    27 changes: 14 additions & 13 deletions codestyle.md
    Original file line number Diff line number Diff line change
    @@ -1,37 +1,38 @@
    ## Code Style

    - Tab indentation
    - Single-quotes
    - Space indentation (2 spaces)
    - Double-quotes
    - Semicolon
    - Strict mode
    - No trailing whitespace
    - Variables at the top of the scope
    - Multiple variable statements
    - Space after keywords and between arguments and operators
    - Always use curly braces
    - Return early
    - JSHint valid
    - Consistency

    Example:

    ```js
    'use strict';
    "use strict";

    function foo(bar, fum) {
    var i, l, ret;
    var hello = 'Hello';
    var i, l, ret;
    var hello = "Hello";

    if (!bar) {
    return;
    }
    if (!bar) {
    return;
    }

    for (i = 0, l = bar.length; i < l; i++) {
    if (bar[i] === hello) {
    ret += fum(bar[i]);
    }
    for (i = 0, l = bar.length; i < l; i++) {
    if (bar[i] === hello) {
    ret += fum(bar[i]);
    }
    }

    return ret;
    return ret;
    }
    ```

  2. @sindresorhus sindresorhus revised this gist Dec 12, 2012. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions codestyle.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,9 @@
    # Code Style
    ## Code Style

    - Tab indentation
    - Single-quotes
    - Semicolon
    - Strict mode
    - No trailing whitespace
    - Variables at the top of the scope
    - Multiple variable statements
    @@ -14,6 +15,8 @@
    Example:

    ```js
    'use strict';

    function foo(bar, fum) {
    var i, l, ret;
    var hello = 'Hello';
    @@ -24,7 +27,7 @@ function foo(bar, fum) {

    for (i = 0, l = bar.length; i < l; i++) {
    if (bar[i] === hello) {
    ret = fum(out);
    ret += fum(bar[i]);
    }
    }

  3. @sindresorhus sindresorhus created this gist Dec 12, 2012.
    35 changes: 35 additions & 0 deletions codestyle.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,35 @@
    # Code Style

    - Tab indentation
    - Single-quotes
    - Semicolon
    - No trailing whitespace
    - Variables at the top of the scope
    - Multiple variable statements
    - Space after keywords and between arguments and operators
    - Return early
    - JSHint valid
    - Consistency

    Example:

    ```js
    function foo(bar, fum) {
    var i, l, ret;
    var hello = 'Hello';

    if (!bar) {
    return;
    }

    for (i = 0, l = bar.length; i < l; i++) {
    if (bar[i] === hello) {
    ret = fum(out);
    }
    }

    return ret;
    }
    ```

    Read [idiomatic.js](https://github.com/rwldrn/idiomatic.js) for general JavaScript code style best practices.