Skip to main content
TOPIC 5 OF 9 · 2 MIN READ

Global Execution Context

The Global Execution Context (GEC) is the default execution context in JavaScript. It is created when the JavaScript code is executed and manages global variables, functions, and objects like window or global.

What you will learn

  • Understand the Global Execution Context (GEC) in JavaScript.
  • Learn what happens during the creation and execution phases of the GEC.

Key concepts

Global Execution Context (GEC)

The environment where global code (not inside any function) is executed.

Phases of Execution Context

Creation Phase: Memory is allocated for variables and functions. Variables are initialized with undefined. Functions are hoisted with their full definitions. Execution Phase: Code is executed line by line, and values are assigned to variables.

Examples

Creation and Execution:

console.log(x); // undefined (hoisted)
var x = 10; // Assigned in execution phase
function greet() {
  console.log('Hello');
}
greet(); // "Hello" (function fully hoisted)

Practise it

Try these without looking back. If you can explain each one out loud, you are ready for this question.

  • Write code that uses global variables and observe their behavior during the creation phase.
  • Predict the output of code involving variable and function declarations.

Stuck on this one? Talk to Sumit.

Keys: F focus mode · ← → previous / next topic · Esc leave focus