diff --git a/javascript/README.md b/javascript/README.md index e69bab9..9a09a3a 100644 --- a/javascript/README.md +++ b/javascript/README.md @@ -88,6 +88,21 @@ var length = items.length; var name = 'foo'; ```` +##Use semi-colons + +There are many more ways that things can break *without* semi-colons then *with* semi-colons. +Use semi-colons! + +```javascript +// bad +a = b +f() // this will evaluate to `a = b f()`, which will be a parse error + +// good +a = b; +f(); +``` + ##Use function expressions over function declarations The function expression is clearly recognisable as what it really is (a variable with a function value). Additionally, it helps organize code so that all variable declarations appear at the top of a file, and invocations follow. This gives some predictablity when others are reading your code, allowing for a more consistent structure. @@ -351,3 +366,17 @@ var title = $('h1'); // good: later on in the code, people will know that they can use jQuery/Zepto on this object var $title = $('h1'); ```` + +##Always use `===` over `==` + +`==` does [implicit coercions](http://dorey.github.io/JavaScript-Equality-Table/), which can +cause a number of unexpected issues. +We always prefer `===` over `==` + +```javascript +// bad +if ("0" == false) {console.log('foo')} // this will console log! bad! + +// good +if ("0" === false) {console.log('foo')} +```