Skip to content

Commit 6e7361b

Browse files
authoredJan 2, 2025··
docs: replace var with let and const in rule example (#19302)
* docs: replace var with let and const * replace more var in no-func-assign
1 parent 069af5e commit 6e7361b

5 files changed

+37
-37
lines changed
 

‎docs/src/rules/no-ex-assign.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Examples of **correct** code for this rule:
4040
try {
4141
// code
4242
} catch (e) {
43-
var foo = 10;
43+
const foo = 10;
4444
}
4545
```
4646

‎docs/src/rules/no-func-assign.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ handled_by_typescript: true
66

77

88

9-
JavaScript functions can be written as a FunctionDeclaration `function foo() { ... }` or as a FunctionExpression `var foo = function() { ... };`. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue.
9+
JavaScript functions can be written as a FunctionDeclaration `function foo() { ... }` or as a FunctionExpression `const foo = function() { ... };`. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue.
1010

1111
```js
1212
function foo() {}
@@ -31,7 +31,7 @@ function baz() {
3131
baz = bar;
3232
}
3333

34-
var a = function hello() {
34+
let a = function hello() {
3535
hello = 123;
3636
};
3737
```
@@ -58,15 +58,15 @@ Examples of **correct** code for this rule:
5858
```js
5959
/*eslint no-func-assign: "error"*/
6060

61-
var foo = function () {}
61+
let foo = function () {}
6262
foo = bar;
6363

6464
function baz(baz) { // `baz` is shadowed.
6565
baz = bar;
6666
}
6767

6868
function qux() {
69-
var qux = bar; // `qux` is shadowed.
69+
const qux = bar; // `qux` is shadowed.
7070
}
7171
```
7272

‎docs/src/rules/no-irregular-whitespace.md

+12-12
Original file line numberDiff line numberDiff line change
@@ -81,43 +81,43 @@ Examples of **incorrect** code for this rule with the default `{ "skipStrings":
8181
```js
8282
/*eslint no-irregular-whitespace: "error"*/
8383

84-
var thing = function() /*<NBSP>*/{
84+
const thing = function() /*<NBSP>*/{
8585
return 'test';
8686
}
8787

88-
var thing = function/*<NBSP>*/){
88+
const foo = function/*<NBSP>*/){
8989
return 'test';
9090
}
9191

92-
var thing = function /*<NBSP>*/(){
92+
const bar = function /*<NBSP>*/(){
9393
return 'test';
9494
}
9595

96-
var thing = function/*<Ogham Space Mark>*/(){
96+
const baz = function/*<Ogham Space Mark>*/(){
9797
return 'test';
9898
}
9999

100-
var thing = function() {
100+
const qux = function() {
101101
return 'test'; /*<ENSP>*/
102102
}
103103

104-
var thing = function() {
104+
const quux = function() {
105105
return 'test'/*<NBSP>*/
106106
}
107107

108-
var thing = function() {
108+
const item = function() {
109109
// Description <NBSP>: some descriptive text
110110
}
111111

112112
/*
113113
Description <NBSP>: some descriptive text
114114
*/
115115

116-
var thing = function() {
116+
const func = function() {
117117
return / <NBSP>regexp/;
118118
}
119119

120-
var thing = function() {
120+
const myFunc = function() {
121121
return `template <NBSP>string`;
122122
}
123123
```
@@ -131,15 +131,15 @@ Examples of **correct** code for this rule with the default `{ "skipStrings": tr
131131
```js
132132
/*eslint no-irregular-whitespace: "error"*/
133133

134-
var thing = function() {
134+
const thing = function() {
135135
return ' <NBSP>thing';
136136
}
137137

138-
var thing = function() {
138+
const foo = function() {
139139
return '​<ZWSP>thing';
140140
}
141141

142-
var thing = function() {
142+
const bar = function() {
143143
return 'th <NBSP>ing';
144144
}
145145
```

‎docs/src/rules/no-new-native-nonconstructor.md

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ It is a convention in JavaScript that global variables beginning with an upperca
1616

1717
```js
1818
// throws a TypeError
19-
let foo = new Symbol("foo");
19+
const foo = new Symbol("foo");
2020

2121
// throws a TypeError
22-
let result = new BigInt(9007199254740991);
22+
const result = new BigInt(9007199254740991);
2323
```
2424

2525
Both `new Symbol` and `new BigInt` throw a type error because they are functions and not classes. It is easy to make this mistake by assuming the uppercase letters indicate classes.
@@ -40,8 +40,8 @@ Examples of **incorrect** code for this rule:
4040
```js
4141
/*eslint no-new-native-nonconstructor: "error"*/
4242

43-
var foo = new Symbol('foo');
44-
var bar = new BigInt(9007199254740991);
43+
const foo = new Symbol('foo');
44+
const bar = new BigInt(9007199254740991);
4545
```
4646

4747
:::
@@ -53,8 +53,8 @@ Examples of **correct** code for this rule:
5353
```js
5454
/*eslint no-new-native-nonconstructor: "error"*/
5555

56-
var foo = Symbol('foo');
57-
var bar = BigInt(9007199254740991);
56+
const foo = Symbol('foo');
57+
const bar = BigInt(9007199254740991);
5858

5959
// Ignores shadowed Symbol.
6060
function baz(Symbol) {

‎docs/src/rules/no-obj-calls.md

+14-14
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,25 @@ Examples of **incorrect** code for this rule:
3939
```js
4040
/*eslint no-obj-calls: "error"*/
4141

42-
var math = Math();
42+
const math = Math();
4343

44-
var newMath = new Math();
44+
const newMath = new Math();
4545

46-
var json = JSON();
46+
const json = JSON();
4747

48-
var newJSON = new JSON();
48+
const newJSON = new JSON();
4949

50-
var reflect = Reflect();
50+
const reflect = Reflect();
5151

52-
var newReflect = new Reflect();
52+
const newReflect = new Reflect();
5353

54-
var atomics = Atomics();
54+
const atomics = Atomics();
5555

56-
var newAtomics = new Atomics();
56+
const newAtomics = new Atomics();
5757

58-
var intl = Intl();
58+
const intl = Intl();
5959

60-
var newIntl = new Intl();
60+
const newIntl = new Intl();
6161
```
6262

6363
:::
@@ -73,13 +73,13 @@ function area(r) {
7373
return Math.PI * r * r;
7474
}
7575

76-
var object = JSON.parse("{}");
76+
const object = JSON.parse("{}");
7777

78-
var value = Reflect.get({ x: 1, y: 2 }, "x");
78+
const value = Reflect.get({ x: 1, y: 2 }, "x");
7979

80-
var first = Atomics.load(foo, 0);
80+
const first = Atomics.load(foo, 0);
8181

82-
var segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });
82+
const segmenterFr = new Intl.Segmenter("fr", { granularity: "word" });
8383
```
8484

8585
:::

0 commit comments

Comments
 (0)
Please sign in to comment.