JavaScript global scope
<p>I ran this code in my console but got undefined. However I expected it to return <code>1</code> because function 2 returns a, which is a var in the global scope. </p>

<p>Can you please explain where I'm mistaken? thank you.</p>

<pre><code>var a = 1;
function f1() {var a = 1; f2();}
function f2() {return a;}
f1();
</code></pre>
