mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-13 23:37:55 -05:00
Reformat var change
This commit is contained in:
20
README.md
20
README.md
@@ -367,6 +367,9 @@
|
||||
```
|
||||
|
||||
- Use one `var` declaration per variable.
|
||||
It's easier to add new variable declarations this way, and you never have
|
||||
to worry about swapping out a `;` for a `,` or introducing punctuation-only
|
||||
diffs.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -374,23 +377,18 @@
|
||||
goSportsTeam = true,
|
||||
dragonball = 'z';
|
||||
|
||||
// bad
|
||||
// (compare to above, and try to spot the mistake)
|
||||
var items = getItems(),
|
||||
goSportsTeam = true;
|
||||
dragonball = 'z';
|
||||
|
||||
// good
|
||||
var items = getItems();
|
||||
var goSportsTeam = true;
|
||||
var dragonball = 'z';
|
||||
```
|
||||
|
||||
It's easier to add new variable declarations this way, and you never have
|
||||
to worry about swapping out a `;` for a `,` or introducing punctuation-only
|
||||
diffs. Also, you can't make the following mistake:
|
||||
|
||||
```javascript
|
||||
// can you catch the error?
|
||||
var items = getItems(),
|
||||
goSportsTeam = true;
|
||||
dragonball = 'z';
|
||||
```
|
||||
|
||||
- Declare unassigned variables last. This is helpful when later on you might need to assign a variable depending on one of the previous assigned variables.
|
||||
|
||||
```javascript
|
||||
|
||||
Reference in New Issue
Block a user