JavaScript Execution Context – How JS Works Behind The Scenes
February 8, 2025 | by author 3

In JavaScript, understanding the concept of execution context is crucial as it defines how JavaScript code runs behind the scenes. An execution context can be seen as an environment in which JavaScript code is executed. There are three types of execution contexts in JavaScript: the global execution context, function execution context, and eval execution context.
The global execution context is the default context in which the JavaScript code runs when it is not inside any function. It includes all the code that is not inside any function. Each JavaScript file has its own global execution context. Variables and functions declared in the global context are accessible throughout the entire script.
Function execution context is created whenever a function is invoked. It includes the code inside the function along with any variables or functions declared within that function. Each time a function is called, a new function execution context is created, forming a stack of contexts known as the call stack. This stack manages the order in which function calls are made and ensures that the functions are executed in the correct sequence.
The
RELATED POSTS
View all