Skip to content

listenerCount()

Returns the number of listeners registered for a given event, or the total number of listeners across all events when called without an argument.

Example

typescript
const count = instance.listenerCount("foo");
// count: 2

const total = instance.listenerCount();
// total: 5

Parameters

ParameterTypeDescription
eventstring | symbol(Optional) The event name. Expects an ESMitterEventName. When omitted, the total listener count across all events is returned.

Returns

TypeDescription
numberThe number of listeners registered for the event, or the total across all events if no argument is given.

Notes

  • If no listeners are registered for the event, 0 is returned.
  • When called without an argument, 0 is returned if no listeners are registered for any event.