Skip to content

Commit 95c7d2d

Browse files
committed
Update Readme according to discussion
1 parent 1ef3333 commit 95c7d2d

File tree

1 file changed

+35
-22
lines changed

1 file changed

+35
-22
lines changed

README.md

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -708,6 +708,14 @@ Other Style Guides
708708
}
709709
}
710710

711+
// good
712+
let test; // if you are planning to reassign value
713+
if (currentUser) {
714+
test = () => {
715+
console.log('Yup.');
716+
};
717+
}
718+
711719
// good
712720
if (currentUser) {
713721
const test = () => {
@@ -1478,7 +1486,7 @@ Other Style Guides
14781486
## Iterators and Generators
14791487
14801488
<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)
14821490
14831491
> Why? This enforces our immutable rule. Dealing with pure functions that return values is easier to reason about than side effects.
14841492
@@ -1639,9 +1647,7 @@ Other Style Guides
16391647
## Variables
16401648
16411649
<a name="variables--const"></a><a name="13.1"></a>
1642-
- [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)
16451651
16461652
```javascript
16471653
// bad
@@ -1750,7 +1756,7 @@ Other Style Guides
17501756
<a name="variables--no-chain-assignment"></a><a name="13.5"></a>
17511757
- [13.5](#variables--no-chain-assignment) Don’t chain variable assignments. eslint: [`no-multi-assign`](https://eslint.org/docs/rules/no-multi-assign)
17521758
1753-
> 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.
17541760
17551761
```javascript
17561762
// bad
@@ -2103,25 +2109,30 @@ Other Style Guides
21032109
const x = 2; // SyntaxError: Identifier 'x' has already been declared
21042110
break;
21052111
case 3:
2112+
// Will be available in entire switch block
21062113
function f() {
21072114
// ...
21082115
}
21092116
break;
21102117
default:
2118+
// Will be available in entire switch block
21112119
class C {}
21122120
}
21132121
21142122
// good
21152123
switch (foo) {
21162124
case 1: {
2125+
// Will be available only in the case 1 block
21172126
let x = 1;
21182127
break;
21192128
}
21202129
case 2: {
2130+
// Will be available only in the case 2 block
21212131
const x = 2; // No SyntaxError
21222132
break;
21232133
}
21242134
case 3: {
2135+
// Will be available only in the case 3 block
21252136
function f() {
21262137
// ...
21272138
}
@@ -2130,7 +2141,8 @@ Other Style Guides
21302141
case 4:
21312142
bar();
21322143
break;
2133-
default: {
2144+
default: {
2145+
// Will be available only in the default block
21342146
class C {}
21352147
}
21362148
}
@@ -2217,7 +2229,10 @@ Other Style Guides
22172229
> Why? It provides precision by distinguishing null/undefined from other falsy values, enhancing code clarity and predictability.
22182230

22192231
```javascript
2220-
// good
2232+
// bad
2233+
const value = 0 ?? 'default'; // 0, not 'default'
2234+
2235+
// bad
22212236
const value = '' ?? 'default'; // '', not 'default'
22222237
22232238
// good
@@ -2242,7 +2257,7 @@ Other Style Guides
22422257
age: 0
22432258
};
22442259
const age = user.age ?? 18; // 0
2245-
const defaultAge = user.age || 18 // 18
2260+
const anotherAge = user.age || 18 // 18
22462261
```
22472262

22482263
**[⬆ back to top](#table-of-contents)**
@@ -2471,7 +2486,7 @@ Other Style Guides
24712486
24722487
```javascript
24732488
// bad
2474-
const isActive = true; // is current tab
2489+
const active = true; // is current tab
24752490
24762491
// good
24772492
// is current tab
@@ -2704,10 +2719,10 @@ Other Style Guides
27042719
// good
27052720
$('#items')
27062721
.find('.selected')
2707-
.highlight()
2708-
.end()
2722+
.highlight()
2723+
.end()
27092724
.find('.open')
2710-
.updateCount();
2725+
.updateCount();
27112726
27122727
// bad
27132728
const leds = stage.selectAll('.led').data(data).enter().append('svg:svg').classed('led', true)
@@ -2716,16 +2731,14 @@ Other Style Guides
27162731
.call(tron.led);
27172732
27182733
// good
2719-
const leds = stage
2720-
.selectAll('.led')
2721-
.data(data)
2722-
.enter()
2723-
.append('svg:svg')
2724-
.classed('led', true)
2725-
.attr('width', (radius + margin) * 2)
2734+
const leds = stage.selectAll('.led')
2735+
.data(data)
2736+
.enter().append('svg:svg')
2737+
.classed('led', true)
2738+
.attr('width', (radius + margin) * 2)
27262739
.append('svg:g')
2727-
.attr('transform', `translate(${radius + margin}, ${radius + margin})`)
2728-
.call(tron.led);
2740+
.attr('transform', `translate(${radius + margin}, ${radius + margin})`)
2741+
.call(tron.led);
27292742
27302743
// good
27312744
const leds = stage.selectAll('.led').data(data);
@@ -3379,7 +3392,7 @@ Other Style Guides
33793392
}
33803393

33813394
// good
3382-
function makeQuery() {
3395+
function query() {
33833396
// ...
33843397
}
33853398
```

0 commit comments

Comments
 (0)