The plus sign in front of the js function, exclamation point, and plus sign in front of the js Function

Source: Internet
Author: User

The plus sign in front of the js function, exclamation point, and plus sign in front of the js Function

+ Function (){}();

The plus sign can also be replaced !,~ And other unary operators, the effect is equivalent:

(Function () {console. log ("Foo! ") ;}) (); // Or (function () {console. log (" Foo! ");}());

Without this plus sign, the parser considers the function as the beginning of a function declaration, and the following () will cause a syntax error. When the + sign is added before the function, it becomes a function expression, and a () is added after the function expression to become a function that is executed immediately.


Reference: http://stackoverflow.com/questions/13341698/javascript-plus-sign-in-front-of-function-name

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.