Home  >  Article  >  Web Front-end  >  +,! in front of JavaScript functions Usage introduction

+,! in front of JavaScript functions Usage introduction

巴扎黑
巴扎黑Original
2017-09-11 11:50:142013browse


+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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn