What is Execution Context in JavaScript?

Execution context is calls on stack that which item is active and which will be executed next.

Image result for javascript execution context
Execution context
Image result for javascript execution context

Whenever Javascript code runs it always runs in Execution context. Global context is always present under the hood.

Keyword ‘this‘ is always present along with global context like ‘window‘ in browser even if there is not any javascript code is present in file.

Keyword ‘this‘ is equal to global context for example in browser this === window returns a true value.

Similarly nodejs have global context of object as global rather than window as in browser as nodejs runs on platform.

This global context object contains all the variable and functions declared in javascript file.

// If we type window in console of empty file then it returns the global 
// object
> window
Output: window object
>var greeting= "hola"
Output: undefined
>window
Output: window object which contains varibale greeting ='hola'

Execution context is just initialization and when javascript code is runs it adds a global function execution on stack and untill the global function execution is not gets popped it remains running.

Read More:

  1. https://hackernoon.com/execution-context-in-javascript-319dd72e8e2c
  2. http://davidshariff.com/blog/what-is-the-execution-context-in-javascript/

Leave a comment