title: let keyword in the for loop
body: <p>ECMAScript 6's <code>let</code> is supposed to provide block scope without hoisting headaches. Can some explain why in the code below <code>i</code> in the function resolves to the last value from the loop (just like with <code>var</code>) instead of the value from the current iteration?</p>
  
  <pre><code>"use strict";
  var things = {};
  for (let i = 0; i &lt; 3; i++) {
      things["fun" + i] = function() {
          console.log(i);
      };
  }
  
  things["fun0"](); // prints 3
  things["fun1"](); // prints 3
  things["fun2"](); // prints 3
  </code></pre>
  
  <p>According to <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/let">MDN</a> using <code>let</code> in the <code>for</code> loop like that should bind the variable in the scope of the loop's body. Things work as I'd expect them when I use a temporary variable inside the block. Why is that necessary?</p>
  
  <pre><code>"use strict";
  var things = {};
  for (let i = 0; i &lt; 3; i++) {
      let index = i;
      things["fun" + i] = function() {
          console.log(index);
      };
  }
  
  things["fun0"](); // prints 0
  things["fun1"](); // prints 1
  things["fun2"](); // prints 2
  </code></pre>
  
  <p>I tested the script with Traceur and <code>node --harmony</code>.</p>