Home > Article > Web Front-end > +,! in front of JavaScript functions Usage introduction
+function(){}();
The plus sign here can also be replaced with !,~ and other unary operators, the effect is equivalent to:
(function() { console.log("Foo!"); })(); // or (function() { console.log("Foo!"); }());
Without this plus sign, the parser will think that function is the beginning of a function declaration, and the following () will cause a syntax error. When a + sign is added in front of function, it becomes a function expression, and when a () is added after the function expression, it becomes an immediately executed function.
The above is the detailed content of +,! in front of JavaScript functions Usage introduction. For more information, please follow other related articles on the PHP Chinese website!