Javascript var vs let (de)optimization/slowdown issue in v8 and SpiderMonkey
During JavaScript code refactoring in my project I've found that some of my loops slowed down drastically. Searching for root cause I've found this SO question stating slowdown is caused by let statement inside for loop and closure creation. To my surprise moving let and closure out of the for loop didn't help, and even using var instead of let for loop variable also does not help because slowdown is caused by let placed after the for loop. By removing extra details I've obtained this code snippet: "use strict" console.log("========================="); (function(){ var itr = 0; function f(){+