Love this trick. It should be noted that the element is added to the window object as long as the id follows the syntax of a valid javascript variable (meaning no dashes).
2. It’s not added to the window object; rather, property lookup on a window object falls back to looking up elements by ID if there is no such property:
> typeof example
"undefined"
> document.body.id = "example";
> example
<body id="example">
> example = "no longer an element";
> example
"no longer an element"
> delete example;
true
> example
<body id="example">
1. It doesn’t need to be a valid JavaScript identifier, though if it isn’t you’ll need to use subscripting syntax to access it:
2. It’s not added to the window object; rather, property lookup on a window object falls back to looking up elements by ID if there is no such property: