Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit 4e8b8d4

Browse files
committed
Merge pull request #64 from mobify/effective-js-ch1
Adding a few new rules based on our book club meeting!
2 parents 91db4f9 + 2bc5470 commit 4e8b8d4

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

javascript/README.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,21 @@ var length = items.length;
8888
var name = 'foo';
8989
````
9090

91+
##Use semi-colons
92+
93+
There are many more ways that things can break *without* semi-colons then *with* semi-colons.
94+
Use semi-colons!
95+
96+
```javascript
97+
// bad
98+
a = b
99+
f() // this will evaluate to `a = b f()`, which will be a parse error
100+
101+
// good
102+
a = b;
103+
f();
104+
```
105+
91106
##Use function expressions over function declarations
92107

93108
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');
351366
// good: later on in the code, people will know that they can use jQuery/Zepto on this object
352367
var $title = $('h1');
353368
````
369+
370+
##Always use `===` over `==`
371+
372+
`==` does [implicit coercions](http://dorey.github.io/JavaScript-Equality-Table/), which can
373+
cause a number of unexpected issues.
374+
We always prefer `===` over `==`
375+
376+
```javascript
377+
// bad
378+
if ("0" == false) {console.log('foo')} // this will console log! bad!
379+
380+
// good
381+
if ("0" === false) {console.log('foo')}
382+
```

0 commit comments

Comments
 (0)