How does JavaScript work? The Easy Way.

Rajesh Bhattarai
2 min readSep 16, 2021

If you want to learn How JavaScript works? in an easy to understand language without any jargon then Hey! you are in the right place.

Photo by Joshua Aragon on Unsplash

First, we need to understand the concept called Execution Context in order to understand How Javascript actually works?

What the heck is Execution context?

Simply put, it is the Environment where all your JavaScript code runs. Every line of code you write gets executed inside the Execution Context. It is like a wrapper that wraps all your amazing codes and starts executing them.

Okay! But I never wrapped my codes in an execution context.

Actually, every time you create a .js file and run your javascript programs an execution context is created.

So How does an execution context works then?

The execution context is created in two pahases:

Phase 1 (Memory creation phase):

In memory creation phase all variables and functions from your javascript programs gets allocated in the memory.

Pahse 2 (Code execution phase):

In code execution phase the javascript programs gets executed. Firstly, a Global Execution Context is created to execute the programs but whenever a function invocation is done a new execution context is created on the top of Global Execution Context. Yes, everytime a function is invoked a new execution context gets created. And as soon as a function returns something, the newly created execution context gets deleted. And at last, when a program is finished the Global Execution Context gets deleted as well.

The manager of all the execution context:

As you know now, at first a Global execution context is created and later everytime a function invocation is done a new execution context gets created. So in order to manage all these bunch of execution context, we have something call Call Stack. All the execution context are placed in the format of stacks in Call Stack. It manages all the creation and deletion of the execution context.

There you go! the simple and easy explaination of How does javascript work?

If you want more such content then do follow me on Twitter LinkedIn and Instagram.

--

--

Rajesh Bhattarai

I am a software developer who loves writing blogs about programming and web development.