title: JavaScript closures and a for loop
body: <p>I was wondering why the result of the following code is 0 and not 3.</p>
  
  <pre><code>var fn = function(){
      for (i = 0; i &lt; 3; i++){
          return function(){
              console.log(i);
          };
      }
  }();
  
  fn();
  </code></pre>