Skip to main content

Command Palette

Search for a command to run...

Come let's see how Javascript works by Aman Verma

Published
โ€ข2 min read
Come let's see how Javascript works by Aman Verma

Hi there! ๐Ÿ˜€ Welcome. Let's learn how javascript works. Get these two points and remember them throughout your life.

  • Everything in javascript happens in execution context.
  • Javascript is a synchronous single-threaded language.

Let's debug both statements one by one.

  • Everything in javascript happens in execution context.

    So what is execution context?

intro EC.png

Execution Context consists of two components i.e. Memory Component (aka variable environment) and Code Component (aka thread in execution).

Execution of the Javascript program happens in two phases:

  • Memory creation phase

mEC-1.png

In this phase, all the variables and function bodies are stored in the memory component of the execution context. Variables are given special keyword as value that is undefined.

  • Execution Phase

exceution phase.png

In this phase, the assignment of values to the variables takes place. Function invocation is also done in this phase. A new execution context is created for every function invocation and is deleted after the execution of that function.

  • Javascript is a synchronous single-threaded language.

Here in the execution phase, all the instructions are executed in order(synchronously) and one instruction executes at a time. (Single Threading)

The creation and deletion of various execution contexts are managed by a call stack.

Call Stack

call stacks.png The call stack maintains an order of execution of execution contexts.


Thank you for reaching up to here. I hope this helps you.

Let's connect! Aman on Linkedin