Search code examples
javascriptgoogle-chromedombrowserwindow

Really - window.document and document inside window is not the same. Chrome


I wonder why one and the same entity has a different representation inside browser window object called in console:

  1. If we call just window inside browser console we'll have a whole browser info. Where the document will be represented as object-liked entity included various props and functions (including DOM).
  2. If we call document directly by window.document command we'll have just only the DOM representation of it.

So, why does it happen? I really cannot figure out.

Thanks.


Solution

  • This is just the way chrome's developer tools work. They have a few different formats that they can output information in the console. Dom nodes, which are a type of object, have gotten their own fancy implementation, since they're such a common occurrence in web development. So when you do window.document, that's the format it chooses to output it.

    For other types of objects they output it in a different format, and that's what it's doing when you do window. It's true you can expand this to drill into window.document, but the dev tools keep displaying it in the same format, rather than trying to nest one format inside another.