2 min readNov 28, 2020
WINDOW, DOCUMENT and SCREEN in JavaScript
Window
- The Window object sits at the top of the JavaScript Object hierarchy and represents the browser window.
- The window object represents the current browsing context . It holds things like window.location, window.history, window.screen, window.status, or the window.document .
- The window is the first thing that gets loaded into the browser and each browser tab has its own top-level window object.
- Also the window property of a window object points to the window object itself. So, all the following statements points to the same window object:
window.window
window.window.window
… so on
Document
- The Document interface represents any web page loaded in the browser and serves as an entry point into the web page’s content, which is the DOM tree.
- When an HTML document is loaded into a web browser , it becomes a document object which is the root node of the HTML document.
- The document actually gets loaded inside the window object and has properties available to it like title, URL, cookie, etc.
- HTML documents, served with the “text/html” content type, also implement the HTMLDocument interface.
- The document property can be accessed in below two ways
document
window.document
As document loads after the window object object is loaded, it sits inside window object.
Screen
- Screen is a small information object about physical screen dimensions .
- It can be used to display screen width, height, colorDepth, pixelDepth etc.
- Screen comes inside window object but its not always mandatory to write window prefix with screen object.
- Some of the property of screen object contains:
screen.width
screen.height
Hope you guys find it useful.
Happy learning!