I am new to JavaScript. I read a code which is:
document.getElementById("myBtn").addEventListener("click", displayDate);
function displayDate() {
document.getElementById("demo").innerHTML = Date();
}
I read the documentation, in this I get that the second parameter of addEventListener would be a function like the bellow (here after function we use () brackets)
document.getElementById("myBtn").addEventListener("click", function(){
document.getElementById("demo").innerHTML = Date();
});
according to my knowledge, we must use () after a function which is not in the first example. Even if I use than it doesn't work. So my question is why we can't use () if we create a separate function. I hope you understand my question.