Global Execution Context
Global Window
Object
"this"
Code to Execute
A wrapper that assists and manages the code that is running.
The lexical environments running are managed by execution contexts. Execution contexts contain values beyond what is written in your code.
Execution Context (Creation Phase)
Global Execution
Context
"this"
Creates Memory space for variables and functions
Outer
Environment
"scope" is a term used to describe what values your program has access to.
"scope" can be determined lexically (based on the physical position of code in your program)
There are two types of "scope", function aka local scope and global scope.
function grace(){
}
function hopper(){
grace();
}
hopper();Global Execution Context
(created and executed)
hopper()
Execution Context
(create and execute)
grace()
Execution Context
(create and execute)
function grace(){
}
function hopper(){
grace();
}
hopper();Global Execution Context
(created and executed)
hopper()
Execution Context
(create and execute)
grace()
Execution Context
(create and execute)
function grace(){
}
function hopper(){
grace();
}
hopper();Global Scope
window = {grace:function(){},
hopper: function(){
grace();
}
} function hopper(){
var myNum;
}
function grace(){
var myNum = 2;
hopper();
}
var myNum = 1;
grace();Global Execution Context
(created and executed)
hopper()
Execution Context
(create and execute)
grace()
Execution Context
(create and execute)
myNum
2
myNum
undefined
myNum
1
function hopper(){
var myNum;
}
function grace(){
var myNum = 2;
hopper();
}
var myNum = 1;
grace();Global Execution Context
(created and executed)
hopper()
Execution Context
(create and execute)
grace()
Execution Context
(create and execute)
myNum
2
myNum
undefined
myNum
1
function hopper(){
var myNum;
}
function grace(){
var myNum = 2;
hopper();
}
var myNum = 1;
grace();Global Execution Context
(created and executed)
hopper()
Execution Context
(create and execute)
grace()
Execution Context
(create and execute)
myNum
2
myNum
undefined
myNum
1
function hopper(){
console.log(myNum);
}
function grace(){
var myNum = 2;
hopper();
}
var myNum = 1;
grace();Global Execution Context
(created and executed)
hopper()
Execution Context
(create and execute)
grace()
Execution Context
(create and execute)
myNum
2
myNum
1
Reference to Outer Lexical Environment
myNum
1