Let it go.

As part of the refinements in es2015/es6 the let statement brings more familiar (saner?) behavior to the language.

As an example, consider this piece of code that creates an array of closures and then invokes them.

function closure(){
  var array = []; 
  for (var i=0; i < 3 ; i++){
    array.push(function() {
      console.log(i);
    })
  }
  return array;
}

closure()[0]();
closure()[1]();
closure()[2]();

This gives the output:

3
3
3

This potentially surprising result is a consequence of the scoping of variables in javascript closures. Even though the i variable is set when the function is created and its value is 0, 1, 2 through each iteration; it is actually the value of i when the closure gets invoked that matters. By using the var statement to create the i variable we are in fact sharing the same variable across each function declaration. Since the terminating condition of the loop occurs when i is equal to (or greater) than 3; the i variable is left with the value 3. When the closures are invoked they simply output this value.

Writing the same code, but this time using let instead of var yeilds a different, and potentially much more familiar, result.

function closure2(){
  var array = []; 
  for (let i=0; i < 3 ; i++){
    array.push(function() {
      console.log(i);
    })
  }
  return array;
}

closure2()[0]();
closure2()[1]();
closure2()[2]();

Output:

0
1
2

In this scenario the i variable that each closure is bound to is a separate instance, and hence maintains its value at the time of the function declaration rather than invocation.