🎙 Free live masterclass · Sun, 29 Nov, 7:00 pm IST · Java Full Stack roadmap Register free →
Skills101
← Quiz: Scope, Closures, Hoisting and this: all 15 questions

Quiz: Scope, Closures, Hoisting and this · Question 14 of 15

What does this print? (code)

What does this print?

function makeAdder(x) {
  return (y) => x + y;
}
const add5 = makeAdder(5);
console.log(add5(2), add5(10));
  1. A.7 7
  2. B.7 15
  3. C.5 10
  4. D.NaN NaN
Answer & explanation

Correct answer: 7 15

The returned function remembers x = 5 through a closure.

Can you get the rest right without peeking?

Take the timed Quiz: Scope, Closures, Hoisting and this quiz free. Pass it to earn XP and count towards your certificate.

Start the quiz →