← JavaScript Interview Questions

JavaScript Events

Create an event emitter that emits an event called `stop`. Also, create an event listener that listens for the stop event you just created. The following code will get you started.

const events = require('events');
const eventEmitter = new events.EventEmitter();
3
1
Asked 9 months ago by Jam Risser

Answers

class events{}
events.EventEmitter = class{
  constructor(){
    return new Event('stop');
  }
}
const eventEmitter = new events.EventEmitter()
document.addEventListener('stop', (e)=>{}, false)
2
Answered 8 months ago by Andrew Butt