title: JavaScript loop variable scope
body: <p>Just a quick question about the scoping of JavaScript variables.</p>
  
  <p>Why does the <code>alert()</code> function print the value of <code>i</code> instead of returning <code>undefined</code>?</p>
  
  <pre><code>$(document).ready(function () {
      for(var i = 0; i &lt; 10; i += 1){
      }
  
       alert("What is 'i'? " + i);
  });
  </code></pre>
  
  <p>I'm fairly new to JS, and in nearly all other languages I've dabbled, a declaration in the scope of the for loop would contain the value to that said loop, but not in this case, why?</p>
  
  <p>i.e. <code>What is 'i'? 10'</code> is printed.</p>