Skip to content

Instantly share code, notes, and snippets.

@sindresorhus
Last active September 26, 2023 07:45

Revisions

  1. sindresorhus revised this gist Feb 13, 2014. 1 changed file with 2 additions and 3 deletions.
    5 changes: 2 additions & 3 deletions codestyle.md
    Original file line number Diff line number Diff line change
    @@ -5,7 +5,6 @@
    - Semicolon
    - Strict mode
    - No trailing whitespace
    - Variables at the top of the scope
    - Multiple variable statements
    - Space after keywords and between arguments and operators
    - Return early
    @@ -18,14 +17,14 @@ Example:
    'use strict';

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

    if (!bar) {
    return;
    }

    for (i = 0, l = bar.length; i < l; i++) {
    for (var i = 0; i < bar.length; i++) {
    if (bar[i] === hello) {
    ret += fum(bar[i]);
    }
  2. 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 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.