Execution Context
Phase 1: Creation
var name = 'Tyler'
var handle = '@tylermcginnis'
function getUser () {
return {
name: name,
handle: handle
}
}
- Create Global Object:Window
- Create Object called: this
- Set up memory space for functions and variables, and assign undefined value to variable, placing functions directly in memories
Phase 2: Execution
Whenever a function is finished running through both the Creation Phase and the Execution Phase, it gets popped off the execution stack.
Any time you pass a variable to a function, that variable during the Creation phase is going to be put in the variable environment of the Current Execution Context. Thus any variable being put in is like a new variable.
Callback Closure
the inner closure still retains the access to the variable of Parent Execution Context, even if the Parent Execution Context has been popped out the Execution Stack. X->5, Y->2, count -> 7