Example 1 — Read the Phase Name
A listener on the clicked element itself usually runs during AT_TARGET.
const names = ["none", "capturing", "target", "bubbling"];
button.addEventListener("click", (event) => {
console.log(event.eventPhase); // 2
console.log(names[event.eventPhase]); // "target"
console.log(event.eventPhase === Event.AT_TARGET); // true
}); How It Works
- Click the button. The listener is on the same element as the click target.
- Phase is 2. That is
Event.AT_TARGET. - Name lookup. Index the friendly names array with
eventPhase. - Prefer constants. Compare with
Event.AT_TARGETinstead of magic2.

