← 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 5 years 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 5 years ago by Andrew Butt