This JavaScript snippet
var x = window.foo;
window.x = null;
alert( window.bar === undefined );
alerts "true".
However, this snippet
var x = window.foo;
window[x] = null;
alert( window.bar === undefined );
alerts "false".
What is going on here?
(I am running this code in the latest Chrome browser inside a HTML page with no other JavaScript code in it.)
Update
As @elusive cleverly summed up in his comment below, I mistakingly assumed that window.x
and window[x]
are equivalent. That is not correct. window.x
is equivalent to window["x"]
.