javascript returns undefind for a globally declared variable
<p>I am a beginer to javascript.I have a doubt.my code is given bellow.when i run this the 1st alert box displaying "undefind".i can not understand why?thanks alot..</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
&lt;script type="text/javascript"&gt;
var a = 123;
   function foo()
   {
     alert(a);
     var a = 890;
     alert(a);
   }
     foo();
     alert(a); 
&lt;/script&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;/body&gt;
&lt;/html&gt;
</code></pre>
