Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions javascript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/then/than/ (grammar police, sorry... :) )

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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.
Expand Down Expand Up @@ -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')}
```