JavaScript Asynchronous Programming with JavaScript Asynchronous JavaScript with Callbacks Callback Functions Review

how do i pass a reference of a function to another function

Question says

Pass addEventListener() a reference to the handleChange function.

function handleChange() { console.log('I was changed!'); }

select.addEventListener('change', __);

[i dont understand what it requires ]

1 Answer

Peter Vann
MOD
Peter Vann
Treehouse Moderator 35,350 Points

Hi Yeukai!

To pass a reference to the handleChange function, simply use the name of the function without the parens.

Like this:

select.addEventListener('change', handleChange);

handleChange referenced this way becomes the callback function for the eventListener.

I hope that helps.

Stay safe and happy coding!