← 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));
- A.7 7
- B.7 15
- C.5 10
- 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 →