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.
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.
// 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);
You can omit the window. prefix since it is implicit — but being explicit helps when window properties might be shadowed.