-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlexical-environment.js
53 lines (40 loc) · 940 Bytes
/
lexical-environment.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
// function a(){
// console.log(b);
// }
// var b=10;
// a();
// //Function a is able to access variable b from Global Scope
function a(){
c();
function c(){
console.log(b);
}
}
var b=10;
a();
// //Within Nested Function too, the global scope variable can be accessed
// function a(){
// c();
// function c(){
// var b=100;
// console.log(b);
// }
// }
// var b=10;
// a();//Execution Context Deleted
// Local variable with the same name took precedence over global variable
function a(){
var b=10;
c();
function c(){
console.log(b);
}
}
a();
console.log(b);
// A function can access the global variable but global execution context cannot
// access local variables
//The variable does not exist in the memory and has no value --> Error
//Referenece Error
// What all variables a function can access
// Local Variables, Variables of the parent Scope