Difference between Window, Document and Screen in JavaScript

Manas Tripathi
1 min readNov 21, 2020

Window

When JavaScript is run in a browser all variables and functions you create are properties and methods of the window object.

You can access but not change any of the properties and methods of the Global object and you can override them be defining a similarly named property or method on the window object but they are still two entirely separate objects.

window is a property of the Global object when you run JavaScript in a web browser

Ex:window.innerHeight ->gives height of browser in pixels.

Document

The document is where the DOM(document object model) is.The document object is your html, aspx, php, or other document that will be loaded into the browser. The document actually gets loaded inside the window object and has properties available to it like title, URL, cookie, etc. What does this really mean? That means if you want to access a property for the window it is window.property, if it is document it is window.document.property which is also available in short as document.property.

Ex:window.document.getElementById(“header”);// gives the value of header.

Screen

The screen is the screen, it contains properties about the user’s display.It can be used to display screen width, height etc..
Ex:
screen.width
screen.height

--

--