1let a = 'hello'; // globally scoped
2var b = 'world'; // globally scoped
3console.log(window.a); // undefined
4console.log(window.b); // 'world'
5var a = 'hello';
6var a = 'world'; // No problem, 'hello' is replaced.
7let b = 'hello';
8let b = 'world'; // SyntaxError: Identifier 'b' has already been declared
1/* DIFFERENCE BETWEEN LET AND VAR */
2
3//LET EXAMPLE
4{
5 let a = 123;
6};
7
8console.log(a); // undefined
9
10//VAR EXAMPLE
11{
12 var a = 123;
13};
14
15console.log(a); // 123