JavaScript - Window - The Browser Object Model Part 1: The window Object as the Global Object
The window object represents the browser window and serves as the global object for JavaScript in the browser.
Examples and Explanation
Accessing Global Variables
var name = "JavaScript";
console.log(window.name); // JavaScript
Explanation: Global variables and functions become properties and methods of the window object.
Accessing Browser-Specific Properties
console.log(window.innerWidth); // Current width of the browser window
console.log(window.innerHeight); // Current height of the browser window
Explanation: The window object provides information about the browser's dimensions.
Using the window Object Implicitly
alert("This is an alert box!"); // Equivalent to window.alert()
Explanation: Methods like alert() and console.log() are part of the window object.