Let's take this stupid piece of code as an example
for (let i = 0; i < 10; i++) {
console.log(
(function (x) {
if (x % 2) {
return 'even';
} else {
return 'odd';
}
})(i)
);
}
Basically, we have an anonymous function that is called multiple times inside a loop, or maybe inside another function. I wonder if it is recreated on every iteration of the cycle or is it optimized somehow? I would appreciate if you could give me a hint on how to find this kind of things on my own. Thanks!
Seems 2.5x slower in Chrome, but the same in Firefox. Seems Firefox was able to inline it. Though an arrow function is slower in Firefox. I guess maybe because of binding
thisandargumentsto the outer scope, but who knows...