I am very confused with the difference between called function with/without parentheses in addEventListener().
Code 1:
var clickerNumber = -1;
var button = document.getElementsByTagName("button")[0];
button.addEventListener("click", clickerCount);
function clickerCount(){
clickerNumber++;
console.log(clickerNumber);
}
Code 2:
var clickerNumber = -1;
var button = document.getElementsByTagName("button")[0];
button.addEventListener("click", clickerCount());
function clickerCount(){
clickerNumber++;
console.log(clickerNumber);
}
Code 1 works when I click the button, it will show the clickernumber, but Code 2 only show 0 in the console and clicking the button does not change the clickernumber. what happens here and whats the mechanism in it?