Functions, Context And Variable Environment
Variable Environment - Where the environment live and how they relate to each other in memory (Where is the variable?)
- Scope!!!!
function b (){
var myVar;
}
function a () {
var myVar = 2;
b();
}
var myVar =1;
a();
- What is the value of myVar?
- Global Execution Context is executed (myVar = 1)
- a() -> New Execution Context is created for a() -
Every execution context has its own execution context so myVar = 2
- b() -> New Execution Context with its own variable environment and memory space so myVar = Undefined
This something to do with scope, where are we able to see the variable.
Each variable is defined in its own execution context, because it is within a function.
Every time you call a function, you get a new execution context