-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLet-var-const.js
105 lines (77 loc) · 1.55 KB
/
Let-var-const.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// {}
// var
// var a;
// a = 10; // can be reassigned
// a = 20;
// var a = 10;
// var a = 20; // can be re-declared
// Let
// let b;
// b = 100;
// let b = 100; // re-declration is not allowed
// let b = 200; // syntax error - Cannot redeclare block-scoped variable 'b'
// let b; // value un-availabe -> undefined -> 100
// console.log(b);
// b = 100;
// Const
// const c; // 'const' declarations must be initialized.
// const c = 200; // Cannot redeclare block-scoped variable 'c'
// block scope/ local
// {
// var a =10;
// let b =20;
// const c = 30;
// }
// console.table(a,b,c); // ReferenceError: b is not defined
// functional scope
// function add() {
// var d = 10;
// let b = 20;
// const c = 30;
// }
// add();
// console.log(d);
// Shadowing
// var a = 10;
// {
// var a = 100;
// let b = 200;
// const c = 300;
// console.table(a, b, c);
// }
// console.table(a); // a inside had shadowed a outside
// let a = 100;
// {
// let a = 200;
// {
// let a = 300;
// console.log(a); // 300
// }
// console.log(a); // 200
// }
// console.log(a); // 100
// Illegal Shadowing
// var a = 100;
// {
// let a = 200;
// console.log(a);
// }
// SyntaxError: Identifier 'a' has already been declared
// let a = 100;
// {
// var a = 200;
// }
let a = 100;
// 100 lines of code
{
let a = 200;
}
// home work questions
for (let i=0; i< 5; i++){
console.log(i);
}
console.log(i); // i acessible here ?
for (var i=0; i< 5; i++){
console.log(i);
}
console.log(i); // i acessible here ?