SyntaxStudy
Sign Up
HTML Intermediate 5 min read

The Window Object

The Window Object

The window object is the global object in browsers. It contains document, location, history, localStorage, and more.

All global variables and functions are properties of window.

Example
// Navigation
window.location.href = "https://example.com";
window.history.back();

// Dimensions
console.log(window.innerWidth, window.innerHeight);

// Timers
const timer = window.setTimeout(() => console.log("3 seconds"), 3000);
window.clearTimeout(timer);
Pro Tip

You can omit the window. prefix since it is implicit — but being explicit helps when window properties might be shadowed.