How JavaScript Works ๐Ÿ”ฅ& Execution Context

ยท

2 min read

To write efficient code, it is crucial to understand the fundamentals of JavaScript. In this article, we will discuss one of the most fundamental concepts of JavaScript, the Execution Context.

Execution Context:

The execution context is a container for JavaScript code. Understanding the execution context is fundamental in JavaScript because it dictates how the code runs.

Components of Execution Context:

Simply put, the execution context is like a big box with two components:

  • memory

  • code.

Execution context comprises two components: the Memory/Variable Environment and the Code/Code Execution.

  1. Variable Environment:

The Variable Environment is responsible for maintaining a list of all the variables and functions in the current scope. It stores all the variables and functions as key-value pairs. Whenever a variable is declared or a function is called, it is stored in the Variable Environment.

  1. Code Execution:

The Code Execution component is responsible for executing the JavaScript code line by line.

JavaScript - a synchronous single-threaded language:

Synchronous means that it can execute only one command at a time. Single-threaded means the code is executed one line at a time, and JavaScript can only handle one thing at a time.

Therefore, it is essential to write optimized and efficient code that executes quickly.


The content of this blog post was inspired by the Ep.1 How JavaScript Works ๐Ÿ”ฅ& Execution Context | Namaste JavaScript Series by Akshay Saini

https://www.youtube.com/watch?v=ZvbzSrg0afE&list=PLlasXeu85E9cQ32gLCvAvr9vNaUccPVNP

ย