Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
218,861 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.