Question 7
Back to Exercise
The code below stops with an uncaught error. Which statement correctly describes the problem?
function makeCounter() {
let n = 0;
return { inc: () => ++n, get: () => n };
}
const counter = makeCounter();
counter();
- A TypeError: counter is not a function – the factory returns an object; call counter.inc() Correct
- B It increments n
- C It returns 0
- D ReferenceError
Correct Answer: Option A
Check what the factory returns: here an object of methods, not a single function.
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!