Twelve Elements of JavaScript Style

I’ve been reading a lot of articles and viewing many presentations on JavaScript. One of the most prolific writer and presenter on the subject is Yahoo!’s Douglas Crockford. I’ve recently rediscovered Crockford’s classic article on The Elements of JavaScript Style (part 2). Between these two articles Crockford lists 12 key elements of JavaScript style.

  • Avoid archaic constructions.
  • Always use blocks in structured statements.
  • Avoid assignment expressions.
  • Use object augmentation.
  • Use common libraries.
  • Watch out for type coercion when using ==.
  • Use the ?: operator to select one of two values.
  • Don’t use the ?: operator to select one of two actions.
  • Use the || operator to specify a default value.
  • Never use implicit global variables.
  • global variables are evil.
  • Use inner functions to avoid global variables.

Related posts:

  1. Dynamically Create HTML Elements with JavaScript
  2. JavaScripts: The Good Parts
  3. Style And Class
  4. Unobtrusive JavaScript with Prototype and Behavior
  5. JavaScript FX
  6. Learning JavaScript


Leave a Reply