Open this example in the interactive library
Source code
const callbacks = [];
for (let index = 0; index < 3; index++) {
callbacks.push(() => index);
}
console.log(callbacks.map((read) => read()));
Sample output
[ 0, 1, 2 ]

Open this example in the interactive library
const callbacks = [];
for (let index = 0; index < 3; index++) {
callbacks.push(() => index);
}
console.log(callbacks.map((read) => read()));
[ 0, 1, 2 ]