We saw how to react to DOM events.
I want to add a line about writing your own custom events.
You can use the Event
object which is provided by the browser, to create a new event, in this case the event named “start”:
const anEvent = new Event('start');
Once you have the event, you can trigger the event using
document.dispatchEvent(anEvent)
and when this happens, any event listener listening on that event “name” is triggered:
document.addEventListener('start', (event) => {
console.log('started!')
})