1. It is a global object for JavaScript code.
  2. It represents the “browser window” and provides methods to control it.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e5cffd2c-5bcd-4d1d-bde0-cc94cab98fb7/Untitled.png

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/0d0233ea-5db2-4735-9bdd-5644e464e119/Untitled.png

for (let i = 0; i < document.body.childNodes.length; i++) {
	console.log(document.body.childNodes[i]);
}

let elem = document.getElementById('MyId');
console.log(elem.childNodes[0] === elem.firstChild);
console.log(elem.childNodes[elem.childNodes.length - 1] === elem.lastChild);
  1. We can use for..of to iterate over it:
  2. Array methods won’t work, because it’s not an array.

Siblings and the Parent

// parent of <body> is <html>
alert(document.body.parentNode === document.documentElement); // true

// after <head> goes <body>
alert(document.head.nextSibling); // HTMLBodyElement

// before <body> goes <head>
alert(document.body.previousSibling); // HTMLHeadElement

Element-only Navigation

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/8363f251-9478-4e6e-a7fc-49a1f499ad71/Untitled.png

alert( document.documentElement.parentNode ); // document
alert( document.documentElement.parentElement ); // null