title: javascript 'let' and 'var' in for-loops
body: <p>On my search for concrete numbers to back usage of the <code>const</code> keyword in Javascript, I stumbled upon a performance comparision between all three variable declaration types var, let and const. I didn't like the test setup, so I created <a href="https://jsperf.com/let-vs-var-forloop/1" rel="nofollow noreferrer">a simplified one</a>.</p>
  
  <p>I didn't expect much difference and Firefox measured up to my expectations:</p>
  
  <p><a href="https://i.stack.imgur.com/RdERw.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/RdERw.jpg" alt="jsPerf results on Firefox 52"></a></p>
  
  <p>But in Chromium something weird happened:</p>
  
  <p><a href="https://i.stack.imgur.com/UcR3L.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UcR3L.jpg" alt="jsPerf results on Chrome 57"></a></p>
  
  <p>Not only are all test results significantly lower but <code>let</code> inside the loop breaks down to a fraction of the speed.</p>
  
  <p>I decided to run the tests in Browserstack to make sure it is not my quirky Linux setup. The same happens there with <code>Firefox 53</code> and <code>Chrome 58</code> on Windows 10. I even tested the somewhat older <code>Chrome 50</code> and got the same behaviour.</p>
  
  <p>What is going on? Is it a bug?</p>
  
  <p><strong>EDIT:</strong> Some commented that the loop is probably just optimized away as it is doing nothing. To show, that this is not the case, I changed <a href="https://jsperf.com/let-vs-var-forloop/1" rel="nofollow noreferrer">the test</a>.</p>