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

Quiz — two counters

What does the program print?

JavaScript
function makeCounter() {
    let count = 0;
    return () => {
        count += 1;
        return count;
    };
}
const a = makeCounter();
const b = makeCounter();
console.log(a(), a(), b());

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