Question about Football Team Cards

So I have passed the step, however I do not understand how the following is working:

playersDropdownList.addEventListener("change", (e) => {
console.log(e.target.value)
});

it is indeed logging the change to the console, but how the heck does (e) equate to the value of the dropdown?

e is the event, which includes the target, the thing that triggered the event. So e.target is the element, which you can get the value of with .value as usual

Ok, then e is just so the .target.value can read info from what caused the event(in this case a change to the dropdown)? Without the e the code doesn’t know where to look for that info, as in if you ran that code segment without the e’s nothing would log to the console?

Just trying to confirm I understand…

I don’t understand… the event is always given to the callback by the event listener, so you can’t have this snippet of code without that

Lol now I’m lost. Are you saying that e is not actually needed? If that’s the case why is it in the callback argument?

Edit: Is e somehow being automatically assigned the element of whatever the .addEventListener is listening to?

the callback function always is passed an argument even if you don’t write a parameter, if you want to capture the argument you can use a parameter

also the arguments object is useful but a bit clunky to use, a parameter is much easier, so we tend to prefer writing a function with parameters instead

1 Like