The differences between the terms window, document, screen and body in JavaScript

Time:2021-6-11

This is discussed in the following stackoverflow clue:

https://stackoverflow.com/que…

The differences between the terms window, document, screen and body in JavaScript

window

Window is the main JavaScript object root, aka the global object in a browser, also can be treated as the root of the document object model. You can access it as window

It is equivalent to the root object in the browser JavaScript programming environment, and can also be regarded as the parent node of the document object model. Is accessed as a global object.

window.screen

An attribute of the window global object, which contains the size information of the physical screen.

window.screen or just screen is a small information object about physical screen dimensions.

window.document

window.document or just document is the main object of the potentially visible (or better yet: rendered) document object model/DOM.

The DOM object corresponding to the visible part of the rendered page.

body

Is a child node named body in the document object described above.

Since window is the global object you can reference any properties of it with just the property name – so you do not have to write down window. – it will be figured out by the runtime.

Because window is a global object, when accessing its properties, the writing of window. Can be omitted.

Therefore, it is also effective to access the properties in the window in the following ways:

The differences between the terms window, document, screen and body in JavaScript

More of Jerry’s original articles are: “Wang Zixi”:
The differences between the terms window, document, screen and body in JavaScript