As we all know, there are two ways to declare a function
function FnA () {alert (' msg ');} Declarative definition function var FnB = function () {alert (' msg ');} function assignment expression definition function
Usually, the way we call a method is functionname ()
However, if we try to add () to the end of a defined function, the parser is incomprehensible.
function msg () {alert (' message ');} ();//parser is not understandable
The calling method of the defined function should be MSG (); So why wrap the function body part in ()?
It turns out that using parentheses to define the function body, the parser will invoke the definition function in the form of a function expression. In other words, any function that can be turned into a function expression can make the parser call the definition function correctly. and! is one of them, and the ~ +-| |, etc. all have this function.
In addition, use! Probably more of a habit problem (omitting one character than the double parenthesis), different operators, the performance is different.
The non-normal invocation mode of JS function