title: How do JavaScript variables work?
body: <p>I know that JavaScript vars point to a value:</p>
  
  <pre><code>var foo = true;
  //... later 
  foo = false;
  </code></pre>
  
  <p>So in that example I've changed <code>foo</code> pointing to <code>true</code> -> <code>foo</code> pointing to <code>false</code>, but if I do:</p>
  
  <pre><code>for (var i=0; i&lt;100; i++){
      var someVar = i;
  }
  </code></pre>
  
  <p>Am I creating a new var for each iteration?</p>
  
  <p>Is there any difference in the following two ways of doing the same?</p>
  
  <pre><code>var myvar;
  for (var i=0; i&lt;100; i++){
      myvar = i;
  }
  </code></pre>
  
  <p>and </p>
  
  <pre><code>for (var i=0; i&lt;100; i++){
      var myvar = i;
  }
  </code></pre>
  
  <p>If so, why?</p>