Skip to content

Commit 9e87e1d

Browse files
committed
[guide] add some more justification for one-var and String() type coercions
1 parent 01fc30b commit 9e87e1d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

README.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ Other Style Guides
590590
<a name="es6-rest"></a>
591591
- [7.6](#7.6) <a name='7.6'></a> Never use `arguments`, opt to use rest syntax `...` instead. [`prefer-rest-params`](http://eslint.org/docs/rules/prefer-rest-params)
592592
593-
> Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`.
593+
> Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`.
594594
595595
```javascript
596596
// bad
@@ -1112,7 +1112,7 @@ Other Style Guides
11121112
11131113
- [13.2](#13.2) <a name='13.2'></a> Use one `const` declaration per variable. eslint: [`one-var`](http://eslint.org/docs/rules/one-var.html) jscs: [`disallowMultipleVarDecl`](http://jscs.info/rule/disallowMultipleVarDecl)
11141114
1115-
> Why? 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.
1115+
> Why? 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. You can also step through each declaration with the debugger, instead of jumping through all of them at once.
11161116

11171117
```javascript
11181118
// bad
@@ -1339,6 +1339,7 @@ Other Style Guides
13391339
```
13401340
13411341
- [15.4](#15.4) <a name='15.4'></a> For more information see [Truth Equality and JavaScript](http://javascriptweblog.wordpress.com/2011/02/07/truth-equality-and-javascript/#more-2108) by Angus Croll.
1342+
13421343
- [15.5](#15.5) <a name='15.5'></a> Use braces to create blocks in `case` and `default` clauses that contain lexical declarations (e.g. `let`, `const`, `function`, and `class`).
13431344

13441345
> Why? Lexical declarations are visible in the entire `switch` block but only get initialized when assigned, which only happens when its `case` is reached. This causes problems when multiple `case` clauses attempt to define the same thing.
@@ -2011,7 +2012,10 @@ Other Style Guides
20112012
// => this.reviewScore = 9;
20122013
20132014
// bad
2014-
const totalScore = this.reviewScore + '';
2015+
const totalScore = this.reviewScore + ''; // invokes this.reviewScore.valueOf()
2016+
2017+
// bad
2018+
const totalScore = this.reviewScore.toString(); // isn't guaranteed to return a string
20152019

20162020
// good
20172021
const totalScore = String(this.reviewScore);

0 commit comments

Comments
 (0)