Differences between window, screen, document in javascript

Vamsi K
Nov 8, 2020

Window🗔:

The window interface represents a window containing a DOM document, it is a top-level hierarchy in javascript and consists of a number of objects in it as properties, and document and screen are one of the objects.

The document property points to the DOM document loaded in that window. A window for a given document can be obtained using the document.defaultView() property.

window is a global variable representing the window in which the script is running, is exposed to JavaScript code.

In a tabbed browser, each tab is represented by its own window object.

Screen💻:

The Screen interface represents a screen, usually, the one on which the current window is being rendered, and is obtained using window.screen.

Note: All browsers determine which screen to report as current by detecting which screen has the center of the browser window.

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.

The DOM tree includes elements such as <body>and <table>, among many others. It provides functionality globally to the document, like how to obtain the page's URL and create new elements in the document.

--

--