Variable Environments:
Where the variable live and how they relate to each other in memory.
function b (){
var myVar;
}
function a () {
var myVar = 2;
b();
}
var myVar = 1;
a();
What is the value of myVar?
- Globar 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 Has something to do with scope.
This means where are able to see the variable. Each variable is defined in its own 'execution context'
as it is within a function.
Every time you call a function, you get a new execution context.
Even though the myVar is declared 3 times, they are uniqued
Summary: