In the code below, I have tried to display alert when the user clicks on the document.As I have done doAlert() with parenthesis, the code runs when the document load and alerts without any events occur but if I do simply
doAlert
It seems to respond when I click the document. So, is it must that I should call function in javascript without the parenthesis or what is the idea for doing this. What if I were to pass parameter to a function.
<!doctype html>
<html>
<head>
<script>
function doAlert(){
alert("Hello");
}
function init(){
document.onclick = doAlert();
}
window.onload = init();
</script>
</head>
<body>
</body>
</html>