As a beginner, I recently attempted the following:
ul.addEventListener("click", function(e) {
console.log("Hi");
});
Surprisingly, this code worked just fine. I learned that the function used here is anonymous. However, when I tried to define the function separately and then pass it in, it resulted in an error:
function myFunc(e) {
console.log("Hi from myFunc");
}
ul.addEventListener("click", myFunc(e));
I'm confused about why this doesn't work. The error message indicates:
Uncaught ReferenceError: e is not defined
at javascript.js:29