Why do variables in the global scope get assigned to the window object?
<pre><code>var foo = 'bar';
console.log(window.foo); // bar
</code></pre>

<p>Seems like variables get assigned as properties to <code>this</code>, but inside anonymous functions, <code>this</code> refers to the parent scope, but doesn't assign variables to the parent scope.</p>

<pre><code>function() {
    var foo = 'bar';
}();

window.foo; // undefined
</code></pre>

<p><strong>What object do variables get assigned to in non-global scopes?</strong></p>
