The global execution context is where your JavaScript code starts running. It sets up the environment so your code can work properly.
0
0
Global execution context in Javascript
Introduction
When your JavaScript program first starts running in a browser or Node.js.
When you want to understand how variables and functions are stored before your code runs.
When debugging to see what variables and functions are available globally.
When learning how JavaScript organizes code execution step-by-step.
Syntax
Javascript
// No direct syntax to write for global execution context // It is created automatically when your program runs
The global execution context is created automatically by JavaScript before your code runs.
It contains the global object (like window in browsers) and sets up the this keyword.
Examples
This code runs inside the global execution context automatically created by JavaScript.
Javascript
console.log('Hello, world!');
Variables and functions declared here are stored in the global execution context before running.
Javascript
var x = 10; function greet() { console.log('Hi!'); } greet();
Sample Program
This program shows how the global execution context stores the variable name and the function sayName. When sayName() runs, it accesses name from the global context.
Javascript
var name = 'Alice'; function sayName() { console.log(name); } sayName();
OutputSuccess
Important Notes
The global execution context is created once when your program starts.
All code outside functions runs inside this global context.
Understanding it helps you know where variables and functions live.
Summary
The global execution context is the first environment JavaScript creates to run your code.
It holds global variables, functions, and the global object.
All code outside functions runs here by default.