JavaScript Execution Context

JavaScript Execution Context

What is JS execution context

Everything in JavaScript happens inside the Execution Context.

We can assume the execution context to be the big box🗃 container in which the whole JavaScript is executed.

So the execution context has 2 components in it.

  1. Memory Component

  2. Code Component

Memory Component / Variable Environment

  • It has a key: value pair to store the variable, and similarly, the functions are also stored here.

  • This memory component is also known as a variable environment.

Code Component / Thread of Execution

  • Here the code is executed one line at a time. also know the thread of execution.

  • The thread of execution is a thread is just thread where the code is executed one line at a time.

JavaScript is a Synchronous Single threaded Language

The reason it's called a thread of execution is that it's like a single thread where the code is executed line by line.

When we say Synchronous Single threaded that means JavaScript can execute single command at a time and that too in a specific order.

This means it can go to the other line only when its previous line is executed, and JavaScript is not possible without this beautiful execution context at all.