Skip to content

OutputNot attempted

Array of functions built with var

var fns = [];
for (var i = 0; i < 3; i++) fns.push(() => i * 10);
console.log(fns[0](), fns[2]());

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

Same single var i shared by all three arrows; after the loop i === 3, so every function returns 30.