1var num = 1; //var can be function or global scoped
2const num = 2; //const can only be block scoped
3let num = 3; //let can only be block scoped
1Const vs Let vs Var
2
3const pi = 3.14
4
5pi = 1
6cannot do this becuase with const you cannot change the value
7
8_____________________________________
9
10
11Let --> is block level
12
13for(let i = 0; i < 3; i++) {
14console.log(i) --> it will console here
15}
16console.log(i) ---> Not here
17
18
19---------------------------------------
20
21Var is for variables available to the entire function
22
23
24for(var j = 0; j < 3; j++) {
25console.log(j) --> it will console here
26}
27console.log(j) ---> it will console here
1// var declares a variable, meaning its value will vary.
2// const declares a constant, meaning its value will remain
3// consistant and not change.
4// If your variable changes throughout the program or website,
5// declare it using a var statement.
6// Otherwise, if its value does not change, declare it using
7// a const statement.
8
9const myConst='A const does not change.';
10
11var myVar='A var does change.';
12
13var myVar=2;
1var makes real ice cubes that rattle around in New York
2let makes real ice cubes in Manhatten
3const is like let but the ice cubes never change because they are plastic
1 var greeter;
2 console.log(greeter); // greeter is undefined
3 greeter = "say hello"
4
1 var tester = "hey hi";
2
3 function newFunction() {
4 var hello = "hello";
5 }
6 console.log(hello); // error: hell
7o is not defined
8