Lesson 25 — Full event emitter
on, off and emit
A full event emitter has three methods: on(event, fn) registers a listener, off(event, fn) removes it, emit(event, data) calls every listener of that event. Removing works by keeping all functions except the one you pass — that is why you must keep a reference to the handler (const h = ...).
[1, 2, 3].filter((x) => x !== 2); // [1, 3]
Why it matters: events let parts of an app talk without knowing about each other — the core of Node and the browser DOM.
Finish off(): keep every listener except f. After off, the second emit must be silent.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based JavaScript Foundations courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for JavaScript Foundations books — check the publication year so the examples match current versions.
Search Amazon →