Skip to content

Instantly share code, notes, and snippets.

@prtksxna
Forked from ritvvijparrikh/js.md
Created November 18, 2013 06:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prtksxna/7523689 to your computer and use it in GitHub Desktop.
Save prtksxna/7523689 to your computer and use it in GitHub Desktop.

General

  • Indentation - 4 spaces
  • Line Length - 80 characters
  • Required License in File Header

Naming

  • variables and functions - lowerCamelCase
  • constructor like functions - UpperCamelCase
  • constants - ALL_UPPER_CASE_WITH_UNDERSCORES

Braces

  • Always use braces and put them on same line even for single line control statements
if (someVar) {
  return true;
} else {
  return null;
}

Note: This wasn't always followed, but any new code should do this.

White Space

  • Space after control statements (if, else, while, for, ...)
if (someVar) {

Equalities

  • Use only strict equalities (and inequalities) in control statements, e.g.
if (someVar === conditionA) {
  return true;
} else if (someVar !== conditionB) {
  return false;
}

Note: This wasn't always followed, but any new code should do this.

Classes

The standard way of creating classes is the following. Please note that by class we mean an object that is class-like. Also, note the naming of all anonymous functions.

var ClassName = (function ClassNameClosure() {
  function ClassName(...) {
    ...
  }

  ClassName.prototype = {
    functionName: function ClassName_functionName(...) {
      ...
    }
  };

  return ClassName;
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment