⏱ 0:02est. 3 min
Chapter 15- Functions, Context, and Variable Environments
Notes
#BIGWORD Variable environment - Where the variables live and how they relate to each other in memory.
Example 1
function b(){
var myVar;
}
function a(){
var myVar = 2;
b();
}
var myVar = 1;
a();
Explanation of example 1
- At first global execution context is created and myVar = 1 is pushed in memory space
- Then it hits invocation of a(), A new execution context is created for a() myVar = 2 into that execution context. Every execution context has it's own variable environment
- Then it invokes b() and new execution context is created for b() myVar = undefined
- This has to do something with scope just means where we are able to see variable each variable is defined in it's own execution context because it's within a function all three myVar are distinct