From the course: JavaScript Essential Training

Unlock this course with a free trial

Join today to access over 22,400 courses taught by industry experts.

Pass arguments through event listeners

Pass arguments through event listeners - JavaScript Tutorial

From the course: JavaScript Essential Training

Pass arguments through event listeners

- [Instructor] Working with the event listeners you'll often want to either access the event object inside the callback function or pass some argument through to the callback function. It's not immediately obvious how to do either when we are working with callback functions. So let's take a closer look. In the earliest example of an event listener, you may remember, I called in the event object as a parameter in the arrow function, and this is the answer to the first part of the question. You see, whenever you set up a new event listener and you have a callback function, the event object is automatically passed to the callback function as an argument, and we can choose to capture that object and use it in the callback function by setting up a parameter name for it. So in this case, I've set up the name event and then we use it down here. The passing of the events object happens automatically. And this is actually the…

Contents