Back to course

The Global Window Object (Browser Environment)

JavaScript: The Complete '0 to Hero' Beginner Course

77. The Global Window Object

When JavaScript runs in a web browser, the global object is the window object. It represents the browser's window and is the root object for the JavaScript environment.

What does window contain?

It contains access to:

  1. Global Variables: Any variable declared globally (using var outside strict mode, or implicitly) becomes a property of the window object.
  2. Browser APIs: Functions for interacting with the browser, like alert(), setTimeout(), and fetch().
  3. The DOM: The entry point to manipulate the web page via the document property.

javascript // alert() is actually window.alert() alert('Hello');

// console.log() is window.console.log()

let x = 10; // In non-strict global scope, this is window.x console.log(window.x); // 10

The document Object

The window object contains the document object, which is the entry point for the Document Object Model (DOM).