Квиз по JavaScript: Closures

This JavaScript closures quiz is built from interview questions. You will trace counters and function factories, solve the classic loop and setTimeout puzzle and see how closures keep data private.

Сложный 10 вопроса ~8 минуты Проходной балл: 80% Node.js 22

Выберите режим

Вы играете как гость: войдите, чтобы сохранить XP и серию.

Пример вопроса

Вопрос 1 из 10

What does this print?

function makeCounter() {
  let count = 0;
  return () => ++count;
}
const next = makeCounter();
next();
next();
console.log(next());
Показать ответ

D. 3 The returned function keeps a link to count even after makeCounter has finished. Each call increases the same count, so the third call returns 3.

Что проверяет этот квиз

  • A function remembers the variables of the scope where it was created
  • Each call to a factory function makes a new, separate closure
  • The var in a loop with setTimeout puzzle and its fixes
  • Closures capture variables, not values
  • Private state, currying and once()

Частые вопросы

Нужен ли аккаунт?

Нет. Играть может любой. Войдите, чтобы сохранять XP, серию, значки и историю.

Можно пройти ещё раз?

Да. Лучший результат сохраняется, а вопросы и ответы каждый раз перемешиваются.