Strangely, window.document is not returning proper object which it should ideally return. Why?

Viewed 93

Case I: (Any general object)

Obj1 = {
 name: "Jack",
 age: 21,
 address: {
  city: "New York",
  street: "Black Street",
  house_no: 39
 }
}

Now, on console.log(Obj1.address) I will get:

 {
  city: "New York",
  street: "Black Street",
  house_no: 39
 }

Case-II: Window.document

Applying same logic - First I will do console.log(window), then console.log(window.document). But, now I don't get the proper structure of window.document (which I should get ideally), but rather I am getting 'dom-structure' (which I should not ideally get).

Now, can someone tell me why is this happening? How to get proper structure inside window.document and not the html dom?

console.log(window);

enter image description here

console.log(window.document);

enter image description here

Now, Can someone please help me understand the issue of why 'window.document' is not providing proper structure of object -- which it should?

1 Answers

When you console.log any DOM element, Chromium will show that element's HTML structure in the console. If you want to examine the Javascript properties of the object, you'll have to use console.dir instead:

enter image description here

(main disadvantage of this is that console.dir accepts only one object as an argument, but console.log can log multiple arguments at once)

Related