title: Why is result different (using var vs. let)?
body: <p>This uses <code>var</code></p>
  
  <pre><code>var a = [];
  for (var i = 0; i &lt; 10; i++) {
      a[i] = function() {
          console.log(i);
      };
  }
  a[6](); // 10
  </code></pre>
  
  <p>This uses <code>let</code></p>
  
  <pre><code>var a = [];
  for (let i = 0; i &lt; 10; i++) {
      a[i] = function() {
          console.log(i);
      };
  }
  a[6](); // 6
  </code></pre>
  
  <p>I don't understand why the result is different. Can somebody guide me?</p>