Skip to content

Commit 49d08a2

Browse files
Mustafa UZUNljharb
authored andcommitted
[readme] prefer const/let over var in examples
2.1 Use const for all of your references; avoid using var. eslint: prefer-const, no-const-assign
1 parent 0d747c6 commit 49d08a2

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

README.md

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ Other Style Guides
778778
> Why? They are confusing to reason about.
779779
780780
```javascript
781-
var b = 1;
781+
let b = 1;
782782
// bad
783783
function count(a = b++) {
784784
console.log(a);
@@ -811,10 +811,10 @@ Other Style Guides
811811
812812
```javascript
813813
// bad
814-
var add = new Function('a', 'b', 'return a + b');
814+
const add = new Function('a', 'b', 'return a + b');
815815

816816
// still bad
817-
var subtract = Function('a', 'b', 'return a - b');
817+
const subtract = Function('a', 'b', 'return a - b');
818818
```
819819
820820
<a name="functions--signature-spacing"></a><a name="7.11"></a>
@@ -1830,14 +1830,14 @@ Other Style Guides
18301830
```javascript
18311831
// bad
18321832
1833-
var some_unused_var = 42;
1833+
const some_unused_var = 42;
18341834
18351835
// Write-only variables are not considered as used.
1836-
var y = 10;
1836+
let y = 10;
18371837
y = 5;
18381838
18391839
// A read for a modification of itself is not considered as used.
1840-
var z = 0;
1840+
let z = 0;
18411841
z = z + 1;
18421842
18431843
// Unused function arguments.
@@ -1851,14 +1851,14 @@ Other Style Guides
18511851
return x + y;
18521852
}
18531853
1854-
var x = 1;
1855-
var y = a + 2;
1854+
const x = 1;
1855+
const y = a + 2;
18561856
18571857
alert(getXPlusY(x, y));
18581858
18591859
// 'type' is ignored even if unused because it has a rest property sibling.
18601860
// This is a form of extracting an object that omits the specified keys.
1861-
var { type, ...coords } = data;
1861+
const { type, ...coords } = data;
18621862
// 'coords' is now the 'data' object without its 'type' property.
18631863
```
18641864
@@ -2892,12 +2892,12 @@ Other Style Guides
28922892
28932893
```javascript
28942894
// bad
2895-
var foo = 1,bar = 2;
2896-
var arr = [1 , 2];
2895+
const foo = 1,bar = 2;
2896+
const arr = [1 , 2];
28972897

28982898
// good
2899-
var foo = 1, bar = 2;
2900-
var arr = [1, 2];
2899+
const foo = 1, bar = 2;
2900+
const arr = [1, 2];
29012901
```
29022902
29032903
<a name="whitespace--computed-property-spacing"></a>
@@ -2907,13 +2907,13 @@ Other Style Guides
29072907
// bad
29082908
obj[foo ]
29092909
obj[ 'foo']
2910-
var x = {[ b ]: a}
2910+
const x = {[ b ]: a}
29112911
obj[foo[ bar ]]
29122912

29132913
// good
29142914
obj[foo]
29152915
obj['foo']
2916-
var x = { [b]: a }
2916+
const x = { [b]: a }
29172917
obj[foo[bar]]
29182918
```
29192919
@@ -2936,11 +2936,11 @@ Other Style Guides
29362936
29372937
```javascript
29382938
// bad
2939-
var obj = { foo : 42 };
2940-
var obj2 = { foo:42 };
2939+
const obj = { foo : 42 };
2940+
const obj2 = { foo:42 };
29412941

29422942
// good
2943-
var obj = { foo: 42 };
2943+
const obj = { foo: 42 };
29442944
```
29452945
29462946
<a name="whitespace--no-trailing-spaces"></a>
@@ -2952,24 +2952,24 @@ Other Style Guides
29522952
<!-- markdownlint-disable MD012 -->
29532953
```javascript
29542954
// bad - multiple empty lines
2955-
var x = 1;
2955+
const x = 1;
29562956

29572957

2958-
var y = 2;
2958+
const y = 2;
29592959

29602960
// bad - 2+ newlines at end of file
2961-
var x = 1;
2962-
var y = 2;
2961+
const x = 1;
2962+
const y = 2;
29632963

29642964

29652965
// bad - 1+ newline(s) at beginning of file
29662966

2967-
var x = 1;
2968-
var y = 2;
2967+
const x = 1;
2968+
const y = 2;
29692969

29702970
// good
2971-
var x = 1;
2972-
var y = 2;
2971+
const x = 1;
2972+
const y = 2;
29732973

29742974
```
29752975
<!-- markdownlint-enable MD012 -->

0 commit comments

Comments
 (0)