In the early days of the web (before standards), IE decided that all named and id'd elements should become implicit global variables. Other browsers followed suit.
Since the window
is the global object, some browsers decided to attach these implicit globals to that. But, because of the danger of an implicit global name conflicting with explicit properties of window
, some user agents decided to attach them to the document
object (where this danger still exists).
When you log window
however, you won't see those implicit properties simply because the browser is keeping them separate from explicit properties.
So, here we are today (20+ years later) and for legacy reasons, you can still refer to a named (or id'd) element just by using its name - no DOM searching. But, because this behavior was never formally standardized and because of the very issue that you bring up with your question, there is confusion about how to use them and why you get a "now you see me, now you don't" behavior.
The moral of the story is, follow standards and stay away from globals, they do more harm than good.
// Implicit global
var g = "global";
console.log(window.g); // "global"
console.log(window); // "g" will be listed