Custom events - when to use

I have recently been reading articles about custom events in JavaScript. It was a topic I largely stumbled upon, but all these articles have told me that custom events are useful.
While they were clear in showing the syntax, I was left none-the-wiser about which situations you might actually use them in, and why they are useful. I would be very curious to hear what they can achieve that you can’t get just as easily with a bunch of functions.

1 Like

With events we have a very limited syntax for their usage. Most commonly it is a click event or a change event on which things are triggered. That tells you what has occurred, but not why.

Using custom events gives you the vocabulary to say why something is happening, which helps to make your code easier to understand.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.