<! DOCTYPE html>
E. AddEventListener("click",demo2) ,Demo2 after the parentheses into the open page directly pop-up dialog box without having to click the button, Without parentheses, the event pop-up dialog is triggered by a click of a button , and I feel that the problem is quite common and confusing, as well as a summary.
function Fun () {
Return 5
}
var a = fun;
var B = Fun ();
A simple function is defined first, which is an instance of a function reference type, so the function is an object. Objects are stored in memory, and the function name fun is a pointer to the object.
var a = fun, which is equivalent to copying a function name pointer to a variable a, the function itself is not copied.
However, if you add parentheses to the fun, it's equivalent to executing immediately, which means that B gets the return value of the function directly.
Then the problem with the above code is:
An event trigger is a function that is called by a user to perform an action that is invoked by the event listener. The AddEventListener () method accepts three parameters, where the second parameter is the function that should be executed when the event is triggered, and if no event is triggered, the function will not be called. If you add parentheses, it is equivalent to not having to listen to the previous event to trigger.
The difference between a JavaScript function and no parentheses