Custom Events
Create and dispatch your own events.
Beyond Built-In Events
The DOM lets you create and dispatch your own events with CustomEvent. This decouples parts of your app: one component announces something happened, others listen without a direct reference.
Creating a CustomEvent
Construct one with new CustomEvent(name, options). The name is any string you choose.
const evt = new CustomEvent("cart:add");
console.log(evt.type); // "cart:add"