Skip to content
Quiz · Closures and this · lesson 5 of 11

Quiz — var in a loop of functions

What does the program print?

JavaScript
const fns = [];
for (var i = 0; i < 3; i++) {
    fns.push(() => i);
}
console.log(fns[0](), fns[1](), fns[2]());

Subscribe to take the course

The course is free. Sign in with Telegram and subscribe to the channel to open every lesson.

Sign in another way