Execution Context

Phase 1: Creation

  1. var name = 'Tyler'
  2. var handle = '@tylermcginnis'
  3. function getUser () {
  4. return {
  5. name: name,
  6. handle: handle
  7. }
  8. }

image.png

  1. Create Global Object:Window
  2. Create Object called: this
  3. 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.
    image.png
    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.
    image.png

    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
    image.png