body{
  text-align:center;
  font-size:4em;
}
// The recursive DFS
Node.prototype.includes = function (node) {
  const currentNode = this;
  if (!currentNode) return false;
  if (currentNode === node) return true;
  let isNodeFound = false;
  for (let index = 0; index < currentNode.childNodes.length; index++) {
    isNodeFound = isNodeFound || currentNode.childNodes[index].includes(node);
    if(isNodeFound) return true;
  }
  return false;
};

// The iterative BFS
Node.prototype.includes = function (node) {
  const queue = [];
  let currentNode = this;
  queue.push(currentNode);
  while (queue.length) {
    currentNode = queue.shift();
    if (currentNode === node) return true;
    if (currentNode.hasChildNodes()) {
      queue.push(...currentNode.childNodes);
    }
  }
  return false;
};

// LCRS
Node.prototype.includes = function (node) {
  const currentNode = this;
  if (!currentNode) return false;
  if (currentNode === node) return true;
  return !!(
    currentNode.firstChild?.includes(node) ||
    currentNode.nextSibling?.includes(node)
  );
};

// ParentNode
Node.prototype.includes = function (node) {
  const currentNode = this;
  while (node) {
    if (currentNode === node) return true;
    node = node.parentNode;
  }
  return false;
};

const isIncluded = document.includes(document.body);
document.body.append(document.createTextNode(isIncluded));

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.