The window object represents the current browsing context. It holds things like window.location
, window.history
, window.screen
, window.status
, or the window.document
. Also, it has information about the framing setup (the frames
, parent
, top
, self
properties), and holds important interfaces such as applicationCache
, XMLHttpRequest
, setTimeout
, escape
, console
or localStorage
. Last but not least it acts as the global scope for JavaScript, i.e. all global variables are properties of it.
In contrast, the (window.
)document object represents the DOM that is currently loaded in the window
- it's just a part of it. A document holds information like the documentElement
(usually
), the forms
collection, the cookie
string, its location
, or its readyState
. It also implements a different interface (there might be multiple Documents, for example an XML document obtained via ajax), with methods like getElementById
or addEventListener
.