Execution Context

Introduction

  • When running a script, new execution context will be put into call stack

  • To define an environment that the code is executed

Scenario

let x = 10;

function timesTen(a){
    return a * 10;
}

let y = timesTen(x);

console.log(y); // 100

Global Execution Context

Creation Phase

  • Create the The Variable Object (VO) which is an object-like container created within an Execution Context

  • For each variable declared with the var keyword, a property is added to VO that points to that variable and is set to 'undefined' (Hoisting)

  • Create this : window

  • Setup a memory heap for storing variables and function references

Execution Phase

  • Execute functions line by line and create function execution context for each

  • Assign variables with value

Function Execution Context

Creation Phase

Create the argument object which refer to the param of function

  • Initialize the variable and param as undefined

  • Create this: window

Execution Phase

  • Execute the code one by one

  • Assign the value declared in the function

References

Last updated

Was this helpful?