TIL, 2020-04-20
What is the difference between window, screen, and document in Javascript?
Window
is the main JS object root, and can also be treated as the root of the DOM.window.screen
or justscreen
is a small information object about physical screen dimensions. The physical display’s full screen.window.document
ordocument
is the main object of the visible document object/model/DOM.- Each browser tab has its own top-level
window
object, and eachiframe
has its ownwindow
too, nested within a parent window.window.window
always refers towindow
, butwindow.parent
andwindow.top
might refer to enclosing windows.window
also has:setTimeout
andsetInterval
, binding event handlers to a timer.location
giving the current URL.history
withback()
andforward()
.navigator
describing the browser software
document
: Eachwindow
has adocument
object to be rendered. Then you can access stuff withdocument.body.something
.- The
document
is your document that gets loaded into the browser.