Skip to content

Commit d9c23c5

Browse files
docs: replace var with const in rule examples (#19325)
1 parent 8e1a898 commit d9c23c5

File tree

5 files changed

+30
-30
lines changed

5 files changed

+30
-30
lines changed

docs/src/rules/no-prototype-builtins.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ Examples of **incorrect** code for this rule:
2222
```js
2323
/*eslint no-prototype-builtins: "error"*/
2424

25-
var hasBarProperty = foo.hasOwnProperty("bar");
25+
const hasBarProperty = foo.hasOwnProperty("bar");
2626

27-
var isPrototypeOfBar = foo.isPrototypeOf(bar);
27+
const isPrototypeOfBar = foo.isPrototypeOf(bar);
2828

29-
var barIsEnumerable = foo.propertyIsEnumerable("bar");
29+
const barIsEnumerable = foo.propertyIsEnumerable("bar");
3030
```
3131

3232
:::
@@ -38,11 +38,11 @@ Examples of **correct** code for this rule:
3838
```js
3939
/*eslint no-prototype-builtins: "error"*/
4040

41-
var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");
41+
const hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");
4242

43-
var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);
43+
const isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);
4444

45-
var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar");
45+
const barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar");
4646
```
4747

4848
:::

docs/src/rules/no-setter-return.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Examples of **incorrect** code for this rule:
3333
```js
3434
/*eslint no-setter-return: "error"*/
3535

36-
var foo = {
36+
const foo = {
3737
set a(value) {
3838
this.val = value;
3939
return value;
@@ -76,7 +76,7 @@ Examples of **correct** code for this rule:
7676
```js
7777
/*eslint no-setter-return: "error"*/
7878

79-
var foo = {
79+
const foo = {
8080
set a(value) {
8181
this.val = value;
8282
}

docs/src/rules/no-sparse-arrays.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ further_reading:
1010
Sparse arrays contain empty slots, most frequently due to multiple commas being used in an array literal, such as:
1111

1212
```js
13-
var items = [,,];
13+
const items = [,,];
1414
```
1515

1616
While the `items` array in this example has a `length` of 2, there are actually no values in `items[0]` or `items[1]`. The fact that the array literal is valid with only commas inside, coupled with the `length` being set and actual item values not being set, make sparse arrays confusing for many developers. Consider the following:
1717

1818
```js
19-
var colors = [ "red",, "blue" ];
19+
const colors = [ "red",, "blue" ];
2020
```
2121

2222
In this example, the `colors` array has a `length` of 3. But did the developer intend for there to be an empty spot in the middle of the array? Or is it a typo?
@@ -34,8 +34,8 @@ Examples of **incorrect** code for this rule:
3434
```js
3535
/*eslint no-sparse-arrays: "error"*/
3636

37-
var items = [,];
38-
var colors = [ "red",, "blue" ];
37+
const items = [,];
38+
const colors = [ "red",, "blue" ];
3939
```
4040

4141
:::
@@ -47,11 +47,11 @@ Examples of **correct** code for this rule:
4747
```js
4848
/*eslint no-sparse-arrays: "error"*/
4949

50-
var items = [];
51-
var items = new Array(23);
50+
const items = [];
51+
const arr = new Array(23);
5252

5353
// trailing comma (after the last element) is not a problem
54-
var colors = [ "red", "blue", ];
54+
const colors = [ "red", "blue", ];
5555
```
5656

5757
:::

docs/src/rules/no-undef.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ Examples of **incorrect** code for this rule:
2222
```js
2323
/*eslint no-undef: "error"*/
2424

25-
var foo = someFunction();
26-
var bar = a + 1;
25+
const foo = someFunction();
26+
const bar = a + 1;
2727
```
2828

2929
:::
@@ -36,8 +36,8 @@ Examples of **correct** code for this rule with `global` declaration:
3636
/*global someFunction, a*/
3737
/*eslint no-undef: "error"*/
3838

39-
var foo = someFunction();
40-
var bar = a + 1;
39+
const foo = someFunction();
40+
const bar = a + 1;
4141
```
4242

4343
:::

docs/src/rules/no-unexpected-multiline.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,20 @@ Examples of **incorrect** code for this rule:
3131
```js
3232
/*eslint no-unexpected-multiline: "error"*/
3333

34-
var foo = bar
34+
const foo = bar
3535
(1 || 2).baz();
3636

37-
var hello = 'world'
37+
const hello = 'world'
3838
[1, 2, 3].forEach(addNumber);
3939

40-
let x = function() {}
40+
const x = function() {}
4141
`hello`
4242

43-
let y = function() {}
43+
const y = function() {}
4444
y
4545
`hello`
4646

47-
let z = foo
47+
const z = foo
4848
/regex/g.test(bar)
4949
```
5050

@@ -57,22 +57,22 @@ Examples of **correct** code for this rule:
5757
```js
5858
/*eslint no-unexpected-multiline: "error"*/
5959

60-
var foo = bar;
60+
const foo = bar;
6161
(1 || 2).baz();
6262

63-
var foo = bar
63+
const baz = bar
6464
;(1 || 2).baz()
6565

66-
var hello = 'world';
66+
const hello = 'world';
6767
[1, 2, 3].forEach(addNumber);
6868

69-
var hello = 'world'
69+
const hi = 'world'
7070
void [1, 2, 3].forEach(addNumber);
7171

72-
let x = function() {};
72+
const x = function() {};
7373
`hello`
7474

75-
let tag = function() {}
75+
const tag = function() {}
7676
tag `hello`
7777
```
7878

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy