window
in the Browserwindow
is the global object that represents the browser window.window.document
→ The page's DOM.window.location.href
→ Gets or sets the current URL.window.localStorage
/ window.sessionStorage
→ Stores key-value pairs.window.innerWidth
/ window.innerHeight
→ Gets viewport dimensions.window.alert(message)
→ Displays an alert box.Accessing window
window
is global, so it's often omitted:console.log(window.location.href);
console.log(location.href); // Same as above
document
in the Browserdocument
is a property of window
(window.document
).document.title
→ Gets or sets the page title.document.body
→ Accesses the <body>
element.document.documentElement
→ Accesses the <html>
element.Accessing document
document
is also global, you can access it directly:console.log(document.title); // Equivalent to `window.document.title`
document.getElementById(id)
→ Selects an element by its ID.document.querySelector(selector)
→ Selects the first matching element.