Do you know what will be the output of this code?
JavaScript
for (let i = 0; i < 3; i++) {
setTimeout(() => console.log(i));
}
Show answer and explanation
The answer is 0 1 2.
With let, each iteration gets a fresh copy of i. Every callback closes over its own binding, so they print the values from their own iteration.