Why does "foo = foo || {};" not work?
<p>I was experimenting around with some javascript in my browser console and and not sure exactly why this doesn't work. The following code in the console and jsfiddle on my attempts throws the error: <em>Uncaught ReferenceError: foo is not defined</em> </p>

<pre><code>foo = foo || {}; 
</code></pre>

<p>The way i interpret this is: if foo of the global object (window in this case) doesn't exist, then create it as an empty object. </p>

<p>Alternatively, the code <code>window.foo = window.foo || {}</code>; works as I would expect. Assigning a value beforehand to foo with <code>foo = 'bar'</code> makes the original statement work when running afterwards as well.</p>
