Object-Oriented / Patterns

Custom Event Emitter

mediumJS SpecificJS / TS5 tests

Problem Statement

Design an `EventEmitter` class with `subscribe(eventName, callback)` and `emit(eventName, args)` methods. `subscribe` should return an unsubscribe handle object with an `unsubscribe()` method.

Examples

Example:
const emitter = new EventEmitter();
const sub = emitter.subscribe('onClick', (x) => console.log(x));
emitter.emit('onClick', [42]); // prints 42
sub.unsubscribe();
JavaScript & TypeScript starter code included
Run this as a live interview

Practice solo

5 test cases. No second person needed.

Get new interview exercises

Practice problems and review drills, sent when we publish new ones. No spam.

Unsubscribe anytime. We never share your address.