← 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();
2
1
Asked 2 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 2 months ago by Andrew Butt