Recall & Review
beginner
What is a 'once' listener in Node.js EventEmitter?
A 'once' listener is an event handler that runs only one time when the event is emitted, then it automatically removes itself.
Click to reveal answer
beginner
How do you add a 'once' listener to an event in Node.js?
Use the
once method on an EventEmitter instance, like emitter.once('eventName', callback).Click to reveal answer
intermediate
Why use a 'once' listener instead of a regular listener?
To handle an event only the first time it happens, avoiding repeated calls and automatically cleaning up the listener.
Click to reveal answer
beginner
What happens if you emit an event multiple times but have a 'once' listener attached?
The 'once' listener runs only on the first emit. Subsequent emits do not trigger it because it removes itself after the first call.
Click to reveal answer
intermediate
Can you remove a 'once' listener before it fires? How?
Yes, by using
emitter.off('eventName', listenerFunction) or emitter.removeListener('eventName', listenerFunction) before the event is emitted.Click to reveal answer
Which method adds a listener that runs only once in Node.js EventEmitter?
✗ Incorrect
The
once() method adds a listener that is called only the first time the event is emitted.What happens to a 'once' listener after it is triggered?
✗ Incorrect
A 'once' listener removes itself automatically after being called once.
How can you remove a 'once' listener before it fires?
✗ Incorrect
You can remove any listener, including 'once' listeners, by calling
off() or removeListener() with the exact listener function.If an event is emitted three times but has a 'once' listener, how many times does the listener run?
✗ Incorrect
The 'once' listener runs only once on the first event emission.
Which of these is NOT true about 'once' listeners?
✗ Incorrect
'Once' listeners do not run multiple times unless re-added explicitly.
Explain what a 'once' listener is and why you might use it in a Node.js application.
Think about events you want to handle only the first time they happen.
You got /4 concepts.
Describe how to add and remove a 'once' listener on an EventEmitter instance.
Focus on the methods and parameters involved.
You got /4 concepts.