LearnFrenzy
Sign in Take a free test

Closures · Exercise 1 of 4

Closures Closures MCQ

  • 15 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Fifteen multiple-choice questions on JavaScript closures: the definition, environments per call, capturing variables, the loop problem, private state, the module pattern, memoization, stale closures, memory and this. Pick an option to check your answer instantly.

Question 11 Hard

What is a "stale closure"?

A A closure that keeps using an old value (a captured copy or a replaced variable) while the code expects the current one
B A closure that has been garbage-collected
C A closure that throws an error
D A closure declared with var
Question page & discussion
Question 12 Hard

Which functions effectively take this from the surrounding scope, the way closures take variables?

A Regular function expressions
B Arrow functions
C Function declarations
D All functions
Question page & discussion
Question 13 Easy

Why does memoize(fn) need a closure?

A To make fn run faster on the first call
B The returned function must keep the cache between calls
C To change fn's parameters
D To prevent fn from being called
Question page & discussion
Question 14 Medium

Why does for (var i = 0; i < 3; i++) fns.push(((n) => () => n)(i)); produce functions returning 0, 1 and 2?

A The IIFE converts var into let
B Each IIFE call creates a new scope with its own parameter n holding the current i
C Arrow functions always copy loop variables
D push copies the value
Question page & discussion
Question 15 Easy

const next = (() => { let n = 0; return () => n++; })(); What does the third call next() return?

A 3
B 1
C 0
D 2
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links