-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathReferences.js
More file actions
39 lines (30 loc) · 819 Bytes
/
References.js
File metadata and controls
39 lines (30 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
//: Use const for all your references; avoid using var. eslint:prefer-const, no-const-assign
/* Why? This ensures that you can't reassign your references, which can lead to bugs and difficult to comprehend code. */
// bad
var a = 1;
var b = 2;
// good
const a = 1;
const b = 2;
//: If you must reassign references, use let instead of var. eslint:no-var
/* Why? let is block-scoped rather than function-spcoped like var. */
// bad
var count = 1;
if (ture) {
count += 1;
}
// good
let count = 1;
if (true) {
count += 1;
}
//: Note that both let and const are block-scoped, whereas var is function-scoped.
// const and let only exist in the blocks they are defined in.
{
let a = 1;
const b = 1;
var c = 1;
}
console.log(a); // ReferenceError
console.log(b); // ReferenceError
console.log(c); // Prints 1