JS Built-ins
EventTargetadvanced

EventTarget β€” listener receives event object

πŸ“– Usage Example
const et = new EventTarget()
const result = et.dispatchEvent(new Event('x', { cancelable: true }))
result  // β†’ true (not cancelled)

dispatchEvent() returns true if the event was not cancelled.

EventTarget β€” event object in listener

Listeners receive the dispatched Event object as their first argument. You can read properties like type from it.

Challenge: Verify that a listener receives an event with the correct type.

πŸ’‘ Hints (1)
  • β€’ The first argument to any event listener is the Event object