title: Javascript Variable Scope - var declared outside of function
body: <p>Apologies if this is a duplicate.  Feel free to direct me if it is. </p>
  
  <p>But WHY Is this the case??</p>
  
  <pre><code>var a = 45; 
  function temp() { 
      b = 34;
  }
  
  alert(b) //34
  
  var a = 45; 
  function temp() { 
      a = 34;
  }
  
  alert(a) // 45 WHY IS THIS 45??? 
  </code></pre>
  
  <p>Shouldn't 34 be assigned globally and then var a is assigned to the global scope initially so 34 overwrites 45?</p>