title: override variable in javascript function
body: <p>Firstly I want to say that I was searching some information about scope variables in javascript (e.g <a href="https://stackoverflow.com/questions/500431/javascript-variable-scope">What is the scope of variables in JavaScript?</a>) and I was trying to understand why my code behaves like that but finally I really don't know. I can't override var a in my function in function, I can do this only using <code>a = 6;</code> without var. Why a is undefined before if statement and overriding this variable ? Why there is no result like this:</p>
  <blockquote>
  <p>5</p>
  <p>equal 5<br />
  equal 6</p>
  </blockquote>
  <p>I have something like this instead:</p>
  <blockquote>
  <p>undefined</p>
  <p>not equal 5<br />
  equal 6</p>
  </blockquote>
  <p>Here's my code:</p>
  <pre><code>    var a = 5;
  
  function something(){
      console.log(a);
      if(a == 5){
          console.log('equal 5')
      }
      else{
          console.log('not equal 5');
      }    
     var a = 6;
      
      function test(){
          if(a == 6){
          console.log('equal 6');
      }
      else{
          console.log('not equal 6')
      }
      }    
      test();    
  }
  something();
  </code></pre>