Flow of code execution in JavaScript

JavaScript is a single-threaded 'interpreted' language, where only one command executes at a time. It has a Synchronous model of execution, where each line is executed line by line, top to bottom.

As soon as you start executing your code, there are two halves to that process:

  1. The process of surfing through the code line by line, referred to as the Thread Of Execution and storage of the bits of data announced while going through the code’s execution in live memory, referred to as the Variable Environment.

  2. In this process the main execution takes place and the javascript runs through the code line by line. Now the number value is changed from undefined to the defined value. Then again above process is repeated with the two phases but only for given functions. After the function is executed completely, the execution context created for that particular function will get deleted automatically. When the whole javascript program is executed completely the GEC will also get deleted.

Together, known as an Execution Context. Where a context is a space where you will execute your code.

There are two types of Execution contexts, Global Execution Context and Local Execution Context.