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

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
215,940 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.

Okay okay I got it thankyou so much Steven Parker .