Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript JavaScript and the DOM (Retiring) 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
229,744 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.