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:
- Global Variables: Any variable declared globally (using
varoutside strict mode, or implicitly) becomes a property of thewindowobject. - Browser APIs: Functions for interacting with the browser, like
alert(),setTimeout(), andfetch(). - The DOM: The entry point to manipulate the web page via the
documentproperty.
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).