Node.js · Junior · Question 41 of 75
What will this code print?
import { EventEmitter } from "node:events";
const bus = new EventEmitter();
bus.once("ping", () => console.log("pong"));
bus.emit("ping");
bus.emit("ping");- ✓Correct answer:
pongonce - 2Nothing
- 3
pongtwice
Explanation
once removes the listener after the first call. With on the listener would run every time.