You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/src/rules/no-new-wrappers.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,29 +12,29 @@ further_reading:
12
12
There are three primitive types in JavaScript that have wrapper objects: string, number, and boolean. These are represented by the constructors `String`, `Number`, and `Boolean`, respectively. The primitive wrapper types are used whenever one of these primitive values is read, providing them with object-like capabilities such as methods. Behind the scenes, an object of the associated wrapper type is created and then destroyed, which is why you can call methods on primitive values, such as:
13
13
14
14
```js
15
-
var text ="Hello world".substring(2);
15
+
consttext="Hello world".substring(2);
16
16
```
17
17
18
18
Behind the scenes in this example, a `String` object is constructed. The `substring()` method exists on `String.prototype` and so is accessible to the string instance.
19
19
20
20
It's also possible to manually create a new wrapper instance:
21
21
22
22
```js
23
-
var stringObject =newString("Hello world");
24
-
var numberObject =newNumber(33);
25
-
var booleanObject =newBoolean(false);
23
+
conststringObject=newString("Hello world");
24
+
constnumberObject=newNumber(33);
25
+
constbooleanObject=newBoolean(false);
26
26
```
27
27
28
28
Although possible, there aren't any good reasons to use these primitive wrappers as constructors. They tend to confuse other developers more than anything else because they seem like they should act as primitives, but they do not. For example:
29
29
30
30
```js
31
-
var stringObject =newString("Hello world");
31
+
conststringObject=newString("Hello world");
32
32
console.log(typeof stringObject); // "object"
33
33
34
-
var text ="Hello world";
34
+
consttext="Hello world";
35
35
console.log(typeof text); // "string"
36
36
37
-
var booleanObject =newBoolean(false);
37
+
constbooleanObject=newBoolean(false);
38
38
if (booleanObject) { // all objects are truthy!
39
39
console.log("This executes");
40
40
}
@@ -55,13 +55,13 @@ Examples of **incorrect** code for this rule:
55
55
```js
56
56
/*eslint no-new-wrappers: "error"*/
57
57
58
-
var stringObject =newString("Hello world");
59
-
var numberObject =newNumber(33);
60
-
var booleanObject =newBoolean(false);
58
+
conststringObject=newString("Hello world");
59
+
constnumberObject=newNumber(33);
60
+
constbooleanObject=newBoolean(false);
61
61
62
-
var stringObject=newString;
63
-
var numberObject=newNumber;
64
-
var booleanObject=newBoolean;
62
+
conststringObject2=newString;
63
+
constnumberObject2=newNumber;
64
+
constbooleanObject2=newBoolean;
65
65
```
66
66
67
67
:::
@@ -73,10 +73,10 @@ Examples of **correct** code for this rule:
Copy file name to clipboardExpand all lines: docs/src/rules/no-octal.md
+4-4Lines changed: 4 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ rule_type: suggestion
8
8
Octal literals are numerals that begin with a leading zero, such as:
9
9
10
10
```js
11
-
var num =071; // 57
11
+
constnum=071; // 57
12
12
```
13
13
14
14
Because the leading zero which identifies an octal literal has been a source of confusion and error in JavaScript code, ECMAScript 5 deprecates the use of octal numeric literals.
@@ -26,8 +26,8 @@ Examples of **incorrect** code for this rule:
26
26
```js
27
27
/*eslint no-octal: "error"*/
28
28
29
-
var num =071;
30
-
var result =5+07;
29
+
constnum=071;
30
+
constresult=5+07;
31
31
```
32
32
33
33
:::
@@ -39,7 +39,7 @@ Examples of **correct** code for this rule:
0 commit comments