JavaScript: If var statements are executed first, then why does this not work?
<p>I tried the following in JavaScript (Firefox 3.5, Windows XP):</p>

<pre><code>(function(){
    window.foobar = 'Welcome!';
})();

var foobar = 'PWN3D!';

alert(foobar);
</code></pre>

<p>The output was 'PWN3D!'. Why did my code PWN me? I thought <code>var name = value;</code> executed first.</p>
