JavaScript simplified - The Components of an Execution Context.

Rakshith Kakathkar
2 min readJan 25, 2021

Ever wondered how JavaScript code gets executed flawlessly??

Have you ever felt the urge to understand what happens behind the scenes of a JavaScript program in depth so that you do not have to break your head while debugging code??

“Well, you are lucky! You have landed in the right place!!”

I will try my level best to make sure you understand the concepts in the simplest way possible in this series called JavaScript simplified, without further ado let us jump into it!

As we all know JavaScript is a Synchronous, Single-threaded language.

A Synchronous language means the code is executed in a specific order. This means a statement is executed only after the completion of its previous statement and single-threaded language means JavaScript can execute only one statement at a time.

When a program is executed, though it looks straightforward to the human eyes a lot of things are happening in the background, and luckily we do not have to worry about this as the compiler takes care of the majority of the things, but we are on a mission to understand it so that we can debug our code more efficiently.

Let us learn about ‘Execution Context’ in this article.

The first step when the program starts executing is the creation of an Execution Context. This Execution Context can be considered as a huge container in which the entire program is executed.

This Global Execution Context has two components within them.

  1. Memory Component.
  2. Code Component.

Let us now try to understand these two components

Memory Component

The memory component is made up of n number of key-value pairs. This component stores all the variables and functions declared within the program. This component is also known as the Variable Environment.

Example of key-value pairs:

  1. a: 10 (Here the key is the variable name ‘a’ and it has 10 stored in it as the value.)
  2. function helloReader(){…..} ( Here the key is the name of the function ‘helloReader’ and it has the entire function definition stored as it’s value.)

Code Component

The code component is the place where the code gets executed. Code component executes the code stored within it line by line. This is also known as The Thread of execution.

In the next blog, let us understand how this execution context is created and the different phases involved in the creation of an Execution Context.

--

--

Rakshith Kakathkar

Hello reader, I am Rakshith Kakathkar a software engineer. I am on a mission to share my knowledge in the simplest way possible!