Chapter XII · Execution Context

Global Execution Context

The Global Execution Context (GEC) is the base execution environment created automatically when a JavaScript script first starts running.

01 How It Works

Think of the foundational ground floor foundation of a multi-story building structure.

The GEC creates the global object (window in browsers, global in Node.js), sets up the 'this' binding pointing to it, and runs the root script.

example.js
const globalApp = "MyApp";
function display() {
  console.log(globalApp);
}
display();
  1. 1. Script loads into memory.

  2. 2. Global Execution Context is pushed to the bottom of the call stack.

  3. 3. Global variables and function declarations are hoisted.

02 Practical Example

Here is how you might see this concept applied in real-world code:

practical.js
console.log(this === window); // true (in browser global context)

Key Takeaway

The Global Execution Context serves as the base environment for all top-level script execution.

Related Concepts