Level 38

The 'error' event

Emitting 'error' with no listener, then again with one.

const { EventEmitter } = require('node:events');const bus = new EventEmitter();try {  bus.emit('error', new Error('no listener'));} catch (e) {  console.log('thrown: ' + e.message);}bus.on('error', (e) => console.log('handled: ' + e.message));bus.emit('error', new Error('listener'));

1. Predict the output

Tap the lines in the order you think they print.

  1. 1…
  2. 2…