Discovered this weird behavior today. If I had the following HTML:
<form>
<h1 id="test">Test</h1>
</form>
Why does this JS work:
console.log(test); // This outputs the <h1> element.
// Why does this work? Shouldn't `test` be undefined?
I haven't declared test
anywhere else. This behavior only seems to happen for elements that are inside a <form>
.