3
I am studying a little Javascript, and I came across a situation that I did not understand very well. The author creates a function and when he will call it by the onclick method he does not put the relatives of the function...
function mostrarAlerta(){
alert("Hello World!");
}
var botao = document.querySelector("button");
botao.onclick = mostrarAlerta;
that is to say, botao.onclick = mostrarAlerta;
in that mostrarAlerta
shouldn’t parentheses come? Like botao.onclick = mostrarAlerta()
?
Got it! Thanks a lot!
– user145848