JavaScript: Different behavior when using dot-notation vs. bracket-notation
<p>This JavaScript snippet  </p>

<pre><code>var x = window.foo;
window.x = null;
alert( window.bar === undefined );
</code></pre>

<p>alerts "true".  </p>

<p>However, this snippet  </p>

<pre><code>var x = window.foo;
window[x] = null;
alert( window.bar === undefined );
</code></pre>

<p>alerts "false".  </p>

<p>What is going on here?  </p>

<p>(I am running this code in the latest Chrome browser inside a HTML page with no other JavaScript code in it.)  </p>

<p><em><strong>Update</em></strong></p>

<p>As @elusive cleverly summed up in his comment below, I mistakingly assumed that <code>window.x</code> and <code>window[x]</code> are equivalent. That is not correct. <code>window.x</code> is equivalent to <code>window["x"]</code>.</p>
