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!