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 Callback Functions in JavaScript Callbacks and the DOM Using the Same Callback on Multiple Elements

karan Badhwar
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
karan Badhwar
Web Development Techdegree Graduate 18,135 Points

event object as a parameter

How can we pass the event object, isn't that suppose to be in the scope of the event handler?

Secondly, we did not even mention that as an argument, so how the event caught is for the Input only? How the event Handler passed the event object.

Lastly, If I pass, It gives error, why so, the event is automatically being passed still?

messageTextArea.addEventListener('focus', focusHandler(e))

1 Answer

Steven Parker
Steven Parker
231,248 Points

The event object argument is passed by the system when it invokes your callback. You don't pass it yourself, you just receive the parameter when your function is called.

For more details, see the MDN page describing the event listener callback.