What happens when a local variable is assigned to global object?
<p>Please ignore that this can be re-written without variables. It's just to have a simple example.</p>

<pre><code>window.onload = function() {
    var a = document.body, b = function() {console.log(1)};
    a.onkeydown = b;
};
</code></pre>

<p>I know what happens: it works. But how?</p>

<p>If <code>b</code> was a global variable, the interpreter would store a reference to it. In this example, does the interpreter store a reference to the local variable, only to replace it, with what I assume is a copy of the function, when the local variable is destroyed? Or is the reference to the local variable still stored somewhere behind the scenes, and is then re-purposed?</p>
