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");

Explanation

once removes the listener after the first call. With on the listener would run every time.

Further reading

Problem with a question

Node.js · Junior · question 41

Test yourself

Take the Node.js · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz