Home > Web Front-end > JS Tutorial > body text

+,! in front of JavaScript functions Usage introduction

巴扎黑
Release: 2017-09-11 11:50:14
Original
1996 people have browsed it


+function(){}();
Copy after login

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!"); }());
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!