JavaScript JavaScript and the DOM Responding to User Interaction Listening for Events with addEventListener()

Which part is the Event Handler?

'To summarize, addEventListener takes an event type and a callback function. This callback function is often called an event handler because its purpose is to handle events, when addEventListener runs it registers the handler on the event target setting the target up to fire the handler any time the event takes place.'

so the 'event handler' is the 'listener' listed on the MDN page shown? or the whole '(type, listener)' combined ? right after he refers to what we have been doing as "click handlers".

2 Answers

Steven Parker
Steven Parker
202,084 Points

I always thought of an "event handler" as the callback function, and the "listener" (as in "addEventListener") as the thing (internal to the system) that invokes the handler when the event happens. But that's not how MDN uses that term.

From the MDN viewpoint, an "event handler" is still the callback function, but a "listener" might be a callback function, or it could also be an object that contains a method that serves as a callback function.

See the MDN page on EventListener for more details.

Ok. thanks for the response Steven.