title: let vs var in javascript
body: <p>I understand that let has block scope and var has functional scope. But I do not understand in this case, how using let will solve the problem</p>
  
  <pre><code>const arr = [1,2,3,4];
  for (var i = 0; i &lt; arr.length; i++) {
  setTimeout(function() {
     console.log(arr[i]) 
  }, 1000);
  } // Prints undefined 5 times
  
  const arr = [1,2,3,4];
  for (let i = 0; i &lt; arr.length; i++) {
  setTimeout(function() {
     console.log(arr[i]) 
  }, 1000);
  } // Prints all the values correctly
  </code></pre>