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: README.md
+35-22Lines changed: 35 additions & 22 deletions
Original file line number
Diff line number
Diff line change
@@ -708,6 +708,14 @@ Other Style Guides
708
708
}
709
709
}
710
710
711
+
// good
712
+
let test; // if you are planning to reassign value
713
+
if (currentUser) {
714
+
test= () => {
715
+
console.log('Yup.');
716
+
};
717
+
}
718
+
711
719
// good
712
720
if (currentUser) {
713
721
consttest= () => {
@@ -1478,7 +1486,7 @@ Other Style Guides
1478
1486
## Iterators and Generators
1479
1487
1480
1488
<a name="iterators--nope"></a><a name="11.1"></a>
1481
-
- [11.1](#iterators--nope) Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for`, `for-in` or `for-of`. eslint: [`no-iterator`](https://eslint.org/docs/rules/no-iterator) [`no-restricted-syntax`](https://eslint.org/docs/rules/no-restricted-syntax)
1489
+
- [11.1](#iterators--nope) Don’t use iterators. Prefer JavaScript’s higher-order functions instead of loops like `for-in` or `for-of`. eslint: [`no-iterator`](https://eslint.org/docs/rules/no-iterator) [`no-restricted-syntax`](https://eslint.org/docs/rules/no-restricted-syntax)
1482
1490
1483
1491
> Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
- [13.1](#variables--const) Always use `const` or `let` to declare variables. Not doing so will result in global variables in case strict mode is disabled. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](https://eslint.org/docs/rules/no-undef) [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
1643
-
1644
-
> Note: The entire contents of JavaScript modules are automatically in [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) and therefore usage of the undeclared variables will not lead to creation of the global variables
1650
+
- [13.1](#variables--const) Always use `const` or `let` to declare variables. Not doing so will result in global variables. We want to avoid polluting the global namespace. Captain Planet warned us of that. eslint: [`no-undef`](https://eslint.org/docs/rules/no-undef) [`prefer-const`](https://eslint.org/docs/rules/prefer-const)
> Why? Chaining variable assignments creates implicit global variables in case [strict mode](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Strict_mode) is disabled.
1759
+
> Why? Chaining variable assignments creates implicit global variables.
1754
1760
1755
1761
```javascript
1756
1762
// bad
@@ -2103,25 +2109,30 @@ Other Style Guides
2103
2109
const x = 2; // SyntaxError: Identifier 'x' has already been declared
2104
2110
break;
2105
2111
case 3:
2112
+
// Will be available in entire switch block
2106
2113
function f() {
2107
2114
// ...
2108
2115
}
2109
2116
break;
2110
2117
default:
2118
+
// Will be available in entire switch block
2111
2119
class C {}
2112
2120
}
2113
2121
2114
2122
// good
2115
2123
switch (foo) {
2116
2124
case 1: {
2125
+
// Will be available only in the case 1 block
2117
2126
let x = 1;
2118
2127
break;
2119
2128
}
2120
2129
case 2: {
2130
+
// Will be available only in the case 2 block
2121
2131
const x = 2; // No SyntaxError
2122
2132
break;
2123
2133
}
2124
2134
case 3: {
2135
+
// Will be available only in the case 3 block
2125
2136
function f() {
2126
2137
// ...
2127
2138
}
@@ -2130,7 +2141,8 @@ Other Style Guides
2130
2141
case 4:
2131
2142
bar();
2132
2143
break;
2133
-
default: {
2144
+
default: {
2145
+
// Will be available only in the default block
2134
2146
class C {}
2135
2147
}
2136
2148
}
@@ -2217,7 +2229,10 @@ Other Style Guides
2217
2229
> Why? It provides precision by distinguishing null/undefined from other falsy values, enhancing code clarity and predictability.
2218
2230
2219
2231
```javascript
2220
-
// good
2232
+
// bad
2233
+
const value = 0 ?? 'default'; // 0, not 'default'
2234
+
2235
+
// bad
2221
2236
const value = '' ?? 'default'; // '', not 'default'
0 commit comments