mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-13 21:48:05 -05:00
[doc] add eslint rule reference for no-new-wrappers
This commit is contained in:
committed by
GitHub
parent
2676cbfb2f
commit
327795bf3c
@@ -2796,11 +2796,14 @@ Other Style Guides
|
||||
- [22.1](#coercion--explicit) Perform type coercion at the beginning of the statement.
|
||||
|
||||
<a name="coercion--strings"></a><a name="21.2"></a>
|
||||
- [22.2](#coercion--strings) Strings:
|
||||
- [22.2](#coercion--strings) Strings: eslint: [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers)
|
||||
|
||||
```javascript
|
||||
// => this.reviewScore = 9;
|
||||
|
||||
// bad
|
||||
const totalScore = new String(this.reviewScore); // typeof totalScore is "object" not "string"
|
||||
|
||||
// bad
|
||||
const totalScore = this.reviewScore + ''; // invokes this.reviewScore.valueOf()
|
||||
|
||||
@@ -2812,7 +2815,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="coercion--numbers"></a><a name="21.3"></a>
|
||||
- [22.3](#coercion--numbers) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](http://eslint.org/docs/rules/radix)
|
||||
- [22.3](#coercion--numbers) Numbers: Use `Number` for type casting and `parseInt` always with a radix for parsing strings. eslint: [`radix`](http://eslint.org/docs/rules/radix) [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers)
|
||||
|
||||
```javascript
|
||||
const inputValue = '4';
|
||||
@@ -2859,7 +2862,7 @@ Other Style Guides
|
||||
```
|
||||
|
||||
<a name="coercion--booleans"></a><a name="21.6"></a>
|
||||
- [22.6](#coercion--booleans) Booleans:
|
||||
- [22.6](#coercion--booleans) Booleans: eslint: [`no-new-wrappers`](https://eslint.org/docs/rules/no-new-wrappers)
|
||||
|
||||
```javascript
|
||||
const age = 0;
|
||||
|
||||
Reference in New Issue
Block a user