mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 07:47:54 -05:00
[guide] add some more justification for one-var and String() type coercions
This commit is contained in:
10
README.md
10
README.md
@@ -590,7 +590,7 @@ Other Style Guides
|
||||
<a name="es6-rest"></a>
|
||||
- [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)
|
||||
|
||||
> Why? `...` is explicit about which arguments you want pulled. Plus rest arguments are a real Array and not Array-like like `arguments`.
|
||||
> Why? `...` is explicit about which arguments you want pulled. Plus, rest arguments are a real Array, and not merely Array-like like `arguments`.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1112,7 +1112,7 @@ Other Style Guides
|
||||
|
||||
- [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)
|
||||
|
||||
> 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.
|
||||
> 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.
|
||||
|
||||
```javascript
|
||||
// bad
|
||||
@@ -1339,6 +1339,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
- [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.
|
||||
|
||||
- [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`).
|
||||
|
||||
> 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
|
||||
// => this.reviewScore = 9;
|
||||
|
||||
// bad
|
||||
const totalScore = this.reviewScore + '';
|
||||
const totalScore = this.reviewScore + ''; // invokes this.reviewScore.valueOf()
|
||||
|
||||
// bad
|
||||
const totalScore = this.reviewScore.toString(); // isn't guaranteed to return a string
|
||||
|
||||
// good
|
||||
const totalScore = String(this.reviewScore);
|
||||
|
||||
Reference in New Issue
Block a user