I'm still quite new to coding so sorry if this is a question with an obvious answer.
I'm using event listeners in JavaScript to toggle the display of a paragraph on a webpage. I can get it to work but am confused as to why certain syntax isn't valid.
If I type moreInfoButtonCourse1.addEventListener("click", toggleDisplay(course1Info));
then nothing happens; the function doesn't work. However if I change this to
moreInfoButtonCourse1.addEventListener("click", () => {
toggleDisplay(course1Info);
});
then it does work. Why is the first option invalid but the second is fine? Thanks!