How is document.querySelector implemented? : <p>I suppose the answer to this question depends on what browser you are using, but I guess that just makes it all the more interesting. </p>

<p>I'm wondering how the <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector" rel="noreferrer"><code>querySelector()</code></a> method is actually implemented. Similarly, I'm curious about <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelectorAll" rel="noreferrer"><code>querySelectorAll()</code></a> and other methods like <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementById" rel="noreferrer"><code>getElementById()</code></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/API/Document/getElementsByClassName" rel="noreferrer"><code>getElementByClassName()</code></a> etc.</p>

<p>Is it a depth first search, breadth first search, or does it utilize some auxiliary data structure, like a global hash table to act as a registry?</p>
