Execution Context simplified

JavaScript engine creates the global execution context before it starts to execute any code. Variables and functions that are not inside any parent function, are accompanied by new execution contexts which are created every time when a new function is executed. This is just like a call stack, one execution context is stacked by other execution contexts belonging to different function executions. This beautiful concept of execution context makes understanding of the javascript more deeper. Execution context is just an environment in which our code is executed and is evaluated.

The global execution context is just like any other execution context, except that it gets created by default and is the parent execution context of all other execution contexts of a particular piece of code. It is associated with the Global object, which means a window object

The execution stack or the calling stack is a simple stack data structure with a LIFO (Last-In-First-Out) implementation, which is used to store all the execution contexts created during execution.

Global Execution Context: Whenever the JavaScript engine receives a script file, it first creates a default Execution Context known as the Global Execution Context (GEC). The GEC is the base/default Execution Context where all JavaScript code that is not inside of a function gets executed.

Function Execution Context: Whenever a function is called, the JavaScript engine creates a different type of Execution Context known as a Function Execution Context (FEC) within the GEC to evaluate and execute the code within that function. Since every function call gets its own FEC, there can be more than one FEC in the run-time of a script.

This article will be completed soon....