Course contentsShow
← Web Development
Lesson 670 of 2,98212. The Document Object ModelFree lesson

The Window Object

Understanding window as the global object in browsers and its relationship to the document.

The Window Object

You'll learn: What the window object is and how it serves as the global container for everything in a browser environment.

The Browser's Top-Level Container

The window object represents the browser window or tab that contains your web page. It's the global object in browser JavaScript—meaning it sits at the very top of the scope chain. Every global variable or function you create automatically becomes a property of window.

Think of window as the entire building that houses your web page. Inside that building, there's a specific room called document (which you've already learned about) that contains your actual DOM tree. But window is bigger—it includes the document, browser history, screen information, and methods for controlling the browser itself.

How Window and Document Relate

The document object is actually a property of window. When you write document.querySelector(), you're really calling window.document.querySelector()—JavaScript just lets you omit the window. prefix because it's implied.

// These are identical:
console.log(document);
console.log(window.document);

// Global variables belong to window:
var myVariable = "Hello";
console.log(window.myVariable); // "Hello"

The window gives you access to browser-specific features like alert(), setTimeout(), and location, while document focuses specifically on the DOM tree content inside the page.

Key Takeaway: The window object is the global object in browsers that contains everything—including the document object—and serves as the implicit parent for all global variables and functions.