Traversing and Comparing Nodes

parentNode, firstChild, lastChild, previousSibling and nextSibling link every node to its neighbors, text nodes included. Identify a node with nodeType (1 element, 3 text, 8 comment, 9 document), nodeName and nodeValue. a === b asks "same object?", isEqualNode() asks "same structure?", contains() tests ancestry, and compareDocumentPosition() returns a bitmask (2 preceding, 4 following, 8 contains, 16 contained by) to test with &.

Walking and comparing nodesHTMLLive
<div id="list" hidden><p><span>1a</span>1b<span>1c</span></p><p>2</p></div>
<pre id="out" style="margin:0"></pre>
<script>
  const list = document.querySelector('#list');
  const t = list.firstChild.firstChild.nextSibling;          // the text node "1b"
  const copy = list.cloneNode(true);
  const [p1, p2] = list.children;
  document.querySelector('#out').textContent = [
    `type/name/value: ${t.nodeType} ${t.nodeName} ${t.nodeValue}`,
    `clone: equal ${copy.isEqualNode(list)}, same ${copy === list}, in DOM ${copy.isConnected}`,
    `p1 vs p2: ${p1.compareDocumentPosition(p2)}, contains: ${list.contains(t)}`,
  ].join('\n');
</script>
Browser output of Listing 8.24
Browser output of 24