-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path47BlokVSfuncScope.js
70 lines (58 loc) · 1.29 KB
/
47BlokVSfuncScope.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
// Block Scope vs Function Scope
// 'let' and 'const' are block scope.
// 'let' and 'const' are Accessable in the same Block.
// 'let' and 'const' are mostly use.
// block #1
{
let firstName = "abhishek";
console.log(firstName);
}
// block #2
{
const firstName = "prithvi";
console.log(firstName);
}
// 'var' is function scope.
// 'var' is accessable from outside of the block.
// "var" is global scope we can acssec it all over code(main function)
{
var firstName = "singh";
}
console.log(firstName);
// use of Block Scope
// #01
// if(ture){
// let firstName = "Abhishek";
// console.log(firstName);
// }
// console.log(firstName); // these will generate error.
// #02
// if(true){
// var firstName1 = "Abhishek";
// console.log(firstName1);
// }
// console.log(firstName1);
// #03 using 'let' & 'const'
function myApp(){
if(true){
let firstName1 = "Abhishek";
console.log(firstName1);
}
if(true){
console.log(firstName1);
}
console.log(firstName1);
}
myApp();
// #04 useing 'var'
// function myApp(){
// if(true){
// var firstName1 = "Abhishek";
// console.log(firstName1);
// }
// if(true){
// console.log(firstName1);
// }
// console.log(firstName1);
// }
// myApp();