Global Execution Context
Topic 5JavaScript Part 1
Global Execution Context
Introduction
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.
Learning Objectives
- •Understand the Global Execution Context (GEC) in JavaScript.
- •Learn what happens during the creation and execution phases of the GEC.
Key Concepts and Definitions
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)Practice Exercises
- •Write code that uses global variables and observe their behavior during the creation phase.
- •Predict the output of code involving variable and function declarations.
Interview guide discussion
(0)Join the discussion — login to comment and help other developers.
Login to comment