Block scope in js : <p>I was playing aroun and found interessting thing</p>

<pre><code>var x = "x";
function a (){
    var x = "y";
  if(1){
    var x = "g";
    alert(x);
  }
  alert(x)
}

a()
</code></pre>

<p>why does this output "g" , "g"  insted of "g" , "y" ? The if creates another block scope and x is local variable inside it which means when i get out of the if block , the outer x ( which equals "y" ) should be printed.</p>
