Execution Context In JavaScript

Rhea RB
2 min readDec 6, 2022

--

What is Execution Context ?
Execution Context is like a big box inside which we store and execute everything.

Why is Execution Context important ?
Everything in JavaScript happens inside a Execution context.

Components of Execution Context.
Memory Component.
1. In memory component, variables and functions are stored as key value pairs.
2. Also known as variable environment.

Code Component
1. In code component, code is executed one line at a time in a specified order.
2. Also known as Code execution Phase.

Example:

let x = 10;

function timesTen(a) {
return a*10
}

let y = timesTen(x);
console.log(y)

Whenever a program is executed the global execution context is created as shown below.

In creation phase, Variables store undefined and functions store the whole code of the function

Execution Phase.

After function execution completes, function execution context is deleted and control is passes to global execution context.
After whole code execution is completed, the global execution context is also deleted.

Call Stack
To keep track of all execution contexts, including the global execution context and function execution contexts, JavaScript engine uses a call stack.

If you liked my blog, please do follow me on : Rhea RB

Thank you for Reading! Happy Coding !!

--

--

Rhea RB

Hello ! I am a senior software engineer, passionate about tech and product.