How JavaScript works? The Execution Context || My Handwritten notes || Part 1

Hello Everyone!

JavaScript is the most hated as well as most loved and popular programming language in the world.

The reason for the hate is because most people don’t understand the underlying beauty of JavaScript.

In this series of posts we will ex…


This content originally appeared on DEV Community and was authored by Swastik Yadav

Hello Everyone!

JavaScript is the most hated as well as most loved and popular programming language in the world.

The reason for the hate is because most people don't understand the underlying beauty of JavaScript.

In this series of posts we will explore:

  • How JavaScript works behind the scene?
  • What is Execution Context?
  • What is Call Stack?
  • What is Hoisting in JavaScript?
  • What is Event Loop?
  • The "this" keyword?

And much more...

I wil keep updating this post with further parts. Now let's dive in.

The Execution Context

Everything in JavaScript happens inside an Execution Context. This Execution Context works in 2 phases.

Both phases are known by multiple names.

  1. Declaration Phase || Memory Allocation Phase || Creation Phase
  2. Execution Phase || Implementation Phase

1 Declaration Phase

In this phase JavaScript scans through the entire code and allocates memory to the variables and functions.

Variables are initialized with Undefined as value.

That's it. This phase don't care about executing the code. It just initializes all the variables with undefined.

2 Execution Phase

In this phase Undefined value of variables are replaced by the actual value.

For all the function calls (invocation) a new Function Execution Context (FEC) is created inside the Global Execution Context (GEC is the main parent execution context).

And this FEC will again follow the entire 2 phase process of execution context.

My handwritten visual notes

Every execution context (global OR function) maintains a memory. For GEC it is the Global Memory and for FEC it is the local memory.

First JavaScript looks in the local memory for a variable if not found then it looks for it in the global memory.

Here are my handwritten visual notes.
execution context notes

execution context notes

I hope these will help.

In part 2 of this series we will discuss about how JS manages all these nested Function Execution Context. The Call Stack.

If you enjoyed it or found useful, please consider joining my weekly Newsletter: https://www.getrevue.co/profile/codeswastik


This content originally appeared on DEV Community and was authored by Swastik Yadav


Print Share Comment Cite Upload Translate Updates
APA

Swastik Yadav | Sciencx (2021-06-03T07:18:14+00:00) How JavaScript works? The Execution Context || My Handwritten notes || Part 1. Retrieved from https://www.scien.cx/2021/06/03/how-javascript-works-the-execution-context-my-handwritten-notes-part-1/

MLA
" » How JavaScript works? The Execution Context || My Handwritten notes || Part 1." Swastik Yadav | Sciencx - Thursday June 3, 2021, https://www.scien.cx/2021/06/03/how-javascript-works-the-execution-context-my-handwritten-notes-part-1/
HARVARD
Swastik Yadav | Sciencx Thursday June 3, 2021 » How JavaScript works? The Execution Context || My Handwritten notes || Part 1., viewed ,<https://www.scien.cx/2021/06/03/how-javascript-works-the-execution-context-my-handwritten-notes-part-1/>
VANCOUVER
Swastik Yadav | Sciencx - » How JavaScript works? The Execution Context || My Handwritten notes || Part 1. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/06/03/how-javascript-works-the-execution-context-my-handwritten-notes-part-1/
CHICAGO
" » How JavaScript works? The Execution Context || My Handwritten notes || Part 1." Swastik Yadav | Sciencx - Accessed . https://www.scien.cx/2021/06/03/how-javascript-works-the-execution-context-my-handwritten-notes-part-1/
IEEE
" » How JavaScript works? The Execution Context || My Handwritten notes || Part 1." Swastik Yadav | Sciencx [Online]. Available: https://www.scien.cx/2021/06/03/how-javascript-works-the-execution-context-my-handwritten-notes-part-1/. [Accessed: ]
rf:citation
» How JavaScript works? The Execution Context || My Handwritten notes || Part 1 | Swastik Yadav | Sciencx | https://www.scien.cx/2021/06/03/how-javascript-works-the-execution-context-my-handwritten-notes-part-1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.