Function scopes and global variables
<pre><code>var foo = '1',
    bar = '2';

console.log(foo, bar, window.foo); //1, 2, undefined

(function(foo){
    console.log(foo, bar); //2, 2
})(bar);
</code></pre>

<p>I have two trivial questions regarding the code above:</p>

<ol>
<li><p>Why is <code>window.foo</code> undefined? Aren't all global variables attached to the window object by default?</p></li>
<li><p>Why is <code>foo ===</code>2 inside of the closure? I know that I'm passing the original <code>bar</code> with the alias <code>foo</code>, which is <code>2</code>, but outside of the function scope <code>foo</code> is still <code>1</code>. And as far as I know, the original <code>foo</code> can be accessed from inside of the closure as well. Is the "new foo" prioritized since it's passed as an argument to the IIFE?</p></li>
</ol>

<p><a href="http://jsfiddle.net/GbeDX/" rel="nofollow">http://jsfiddle.net/GbeDX/</a></p>
