forked from DouglasHdezT/JavaScript_NodeCourse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample1.js
More file actions
66 lines (48 loc) · 1.11 KB
/
Example1.js
File metadata and controls
66 lines (48 loc) · 1.11 KB
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
/**
* Scope Rules
*/
function showVarScope(){
console.log("-----Showing var scope-----")
var number1 = 1997;
if(true){
var number1 = 2020;
console.log("Inside if: " + number1);
}
console.log("Outside if: " + number1);
/**
* They are the same variable
*/
}
function showLetScope(){
console.log("-----Showing let scope-----")
let number1 = 1997;
if(true){
let number1 = 2020;
console.log("Inside if: " + number1);
}
console.log("Outside if: " + number1);
/**
* They are diferent variables
*/
}
function showPractcalScope(){
console.log("-----Showing a practical example-----");
var a = 10;
var b = 3
console.log("Before if");
console.log("a = " + a);
console.log("b = " + b);
if(a == 10){
console.log("Inside if");
let a = 6;
var b = 10;
console.log("a = " + a);
console.log("b = " + b);
}
console.log("Outside if");
console.log("a = " + a);
console.log("b = " + b);
}
showVarScope();
showLetScope();
showPractcalScope();