The home where you level up

Save my spot

.eventPhase

Term side of the Card.
Topic: Event
Unit title: .eventPhase
Categories: Property
Explanation side of the Card

Explanation: The browser API property that indicates the current phase of event propagation, returning an integer. Possible phases include no processing, capturing phase, target phase and bubbling phase.

Browser compatibility:
  • The chrome browser supports this feature starting from version 1.
  • The edge browser supports this feature starting from version 12.
  • The firefox browser supports this feature starting from version 1.5.
  • The safari browser supports this feature starting from version 1.
Availability: 

Example

js
parent.addEventListener('click', (e) => {
  if (e.eventPhase === Event.BUBBLING_PHASE) log('bubbling');
});

eventPhase returns the current propagation phase, and Event.BUBBLING_PHASE ('3') matches a click bubbling up from a child.

Common mistakes

  • Reading eventPhase after the handler finished and getting 0.

Key points

  • Code compares eventPhase to constants like Event.CAPTURING_PHASE, Event.AT_TARGET and Event.BUBBLING_PHASE, not bare numbers.
  • Listeners that must run before target handlers are added with { capture: true }.

Interview questions

What are the possible values of eventPhase?

0 is NONE, 1 is CAPTURING_PHASE, 2 is AT_TARGET and 3 is BUBBLING_PHASE.

Why is eventPhase 0?

0 means NONE: the event is not being dispatched, for example when read after the handler returned or before dispatchEvent().

The home where you level up

Daily 3-minute lessons to understand your AI's code.

No spam — just launch news.
Unsubscribe anytime. · Privacy Policy

Analytics cookiesWe'd like to use analytics cookies to see which pages are useful. They're set only if you accept. Privacy Policy