Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between window, screen, and document in JavaScript?

Tags:

javascript

I see these terms used interchangeably as the global environment for the DOM. What is the difference (if there is one) and when should I use each one?

like image 890
TimeEmit Avatar asked Mar 27 '12 18:03

TimeEmit


1 Answers

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

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

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

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.

like image 187
Peter Aron Zentai Avatar answered Sep 18 '22 15:09

Peter Aron Zentai