@@ -778,7 +778,7 @@ Other Style Guides
778
778
> Why? They are confusing to reason about.
779
779
780
780
` ` ` javascript
781
- var b = 1 ;
781
+ let b = 1 ;
782
782
// bad
783
783
function count (a = b ++ ) {
784
784
console .log (a);
@@ -811,10 +811,10 @@ Other Style Guides
811
811
812
812
` ` ` javascript
813
813
// bad
814
- var add = new Function (' a' , ' b' , ' return a + b' );
814
+ const add = new Function (' a' , ' b' , ' return a + b' );
815
815
816
816
// still bad
817
- var subtract = Function (' a' , ' b' , ' return a - b' );
817
+ const subtract = Function (' a' , ' b' , ' return a - b' );
818
818
` ` `
819
819
820
820
<a name="functions--signature-spacing"></a><a name="7.11"></a>
@@ -1830,14 +1830,14 @@ Other Style Guides
1830
1830
```javascript
1831
1831
// bad
1832
1832
1833
- var some_unused_var = 42;
1833
+ const some_unused_var = 42;
1834
1834
1835
1835
// Write-only variables are not considered as used.
1836
- var y = 10;
1836
+ let y = 10;
1837
1837
y = 5;
1838
1838
1839
1839
// A read for a modification of itself is not considered as used.
1840
- var z = 0;
1840
+ let z = 0;
1841
1841
z = z + 1;
1842
1842
1843
1843
// Unused function arguments.
@@ -1851,14 +1851,14 @@ Other Style Guides
1851
1851
return x + y;
1852
1852
}
1853
1853
1854
- var x = 1;
1855
- var y = a + 2;
1854
+ const x = 1;
1855
+ const y = a + 2;
1856
1856
1857
1857
alert(getXPlusY(x, y));
1858
1858
1859
1859
// ' type' is ignored even if unused because it has a rest property sibling.
1860
1860
// This is a form of extracting an object that omits the specified keys.
1861
- var { type, ...coords } = data;
1861
+ const { type, ...coords } = data;
1862
1862
// ' coords' is now the ' data' object without its ' type' property.
1863
1863
```
1864
1864
@@ -2892,12 +2892,12 @@ Other Style Guides
2892
2892
2893
2893
` ` ` javascript
2894
2894
// bad
2895
- var foo = 1 ,bar = 2 ;
2896
- var arr = [1 , 2 ];
2895
+ const foo = 1 ,bar = 2 ;
2896
+ const arr = [1 , 2 ];
2897
2897
2898
2898
// good
2899
- var foo = 1 , bar = 2 ;
2900
- var arr = [1 , 2 ];
2899
+ const foo = 1 , bar = 2 ;
2900
+ const arr = [1 , 2 ];
2901
2901
` ` `
2902
2902
2903
2903
<a name="whitespace--computed-property-spacing"></a>
@@ -2907,13 +2907,13 @@ Other Style Guides
2907
2907
// bad
2908
2908
obj[foo ]
2909
2909
obj[ ' foo' ]
2910
- var x = {[ b ]: a}
2910
+ const x = {[ b ]: a}
2911
2911
obj[foo[ bar ]]
2912
2912
2913
2913
// good
2914
2914
obj[foo]
2915
2915
obj[' foo' ]
2916
- var x = { [b]: a }
2916
+ const x = { [b]: a }
2917
2917
obj[foo[bar]]
2918
2918
` ` `
2919
2919
@@ -2936,11 +2936,11 @@ Other Style Guides
2936
2936
2937
2937
` ` ` javascript
2938
2938
// bad
2939
- var obj = { foo : 42 };
2940
- var obj2 = { foo: 42 };
2939
+ const obj = { foo : 42 };
2940
+ const obj2 = { foo: 42 };
2941
2941
2942
2942
// good
2943
- var obj = { foo: 42 };
2943
+ const obj = { foo: 42 };
2944
2944
` ` `
2945
2945
2946
2946
<a name="whitespace--no-trailing-spaces"></a>
@@ -2952,24 +2952,24 @@ Other Style Guides
2952
2952
<!-- markdownlint-disable MD012 -->
2953
2953
` ` ` javascript
2954
2954
// bad - multiple empty lines
2955
- var x = 1 ;
2955
+ const x = 1 ;
2956
2956
2957
2957
2958
- var y = 2 ;
2958
+ const y = 2 ;
2959
2959
2960
2960
// bad - 2+ newlines at end of file
2961
- var x = 1 ;
2962
- var y = 2 ;
2961
+ const x = 1 ;
2962
+ const y = 2 ;
2963
2963
2964
2964
2965
2965
// bad - 1+ newline(s) at beginning of file
2966
2966
2967
- var x = 1 ;
2968
- var y = 2 ;
2967
+ const x = 1 ;
2968
+ const y = 2 ;
2969
2969
2970
2970
// good
2971
- var x = 1 ;
2972
- var y = 2 ;
2971
+ const x = 1 ;
2972
+ const y = 2 ;
2973
2973
2974
2974
` ` `
2975
2975
<!-- markdownlint-enable MD012 -->
0 commit comments