I know that document
is an object inside window
(the global object) and is also called the Document Object Model which contains all the functionalities required to manipulate itself.
My understanding is that the Document Object Model is a broader API than just the document
object, which is "the entry point to the page's content" according to MDN.
However, when I open the console and type window.document
, the value returned is an object that does not contain any functions or properties.
That's not true. The value returned does have all of the functions and properties of document
; in fact, it's the exact document
object. You're probably confusing the browser-specific representation shown in your screenshot starting with #document
with the actual return value.
You can prove this to yourself with an assignment: foo = document
. Then type foo.
on the next line and the exact same autocomplete will appear that shows when you type document.
directly, because foo
is just an alias of document
. You can call foo.querySelector("p")
and it'll work just fine. If you type foo
or document
and press Enter, you'll see the abbreviated #document
representation.
In Firefox 102.0.1, the same code (typing document
and pressing Enter) shows something else:

Even though it looks different, all of the programmatic logic you might perform on the returned value will work just the same as Chrome (notwithstanding the normal browser-specific implementation differences of the ECMAScript spec).
I don't understand the meaning of the #
sign
The #
is a Chrome-specific way of denoting the element as a "virtual" element that you can't select. It's used in the element tree and for frames and shadow roots. As you can see from the Firefox screenshot above, no #
appears.
and when I expand it, it only contains the HTML elements with no functions or properties. But when I type document.
, a list of suggestions of all the available methods appears.
For whatever reason, Chrome has decided that showing the HTML tree is a more useful representation of a DOM object for console.log
rather than the properties and methods of the object. (console.log
is automatically invoked on whatever expression you run in the console)
To see the object displayed in a similar format as the Firefox screenshot above, use console.dir(document)
. This seems to be more like what you were expecting, showing that the return value indeed has all of the properties and methods of document
.
Don't confuse how browsers choose to display information in console.log()
with what the variables and objects actually represent in the program. These are two totally different things, and browsers often elide many properties from things that are logged, present them as very different from the typical JSON representation you might expect, or live-update the logged object, leading to confusion.
See What does a key value pair inside the square brackets [] mean? for a further dive into the implementation-defined nature of logging:
An object with generic JavaScript object formatting is a potentially expandable representation of a generic JavaScript object. An object with optimally useful formatting is an implementation-specific, potentially-interactive representation of an object judged to be maximally useful and informative.
Used in this post: Chrome 103.0.5060.114 (Official Build) (64-bit)