为什么我可以在不使用getElementById()的情况下访问表单中的元素?

saa*_*adq 5 html javascript forms dom

今天发现了这种奇怪的行为.如果我有以下HTML:

<form>
  <h1 id="test">Test</h1>
</form>
Run Code Online (Sandbox Code Playgroud)

为什么这个JS工作:

console.log(test); // This outputs the <h1> element. 
                   // Why does this work? Shouldn't `test` be undefined?
Run Code Online (Sandbox Code Playgroud)

我还没有宣布test其他地方.这种行为似乎只发生在一个内部的元素<form>.