The meaning of function () {/* do something */}) ();, JavaScript, functionsomething

Source: Internet
Author: User

The meaning of function () {/* do something */}) ();, JavaScript, functionsomething


Run the anonymous function, and the variables in the anonymous function do not pollute the global variable space.


Code:


<Html> 



Execution result:

Function 0 has no return value, runs, and does not pollute the space of the global variable I am running in a function anonymous. var inside undefined: falsevar inside values: inside function 1 returns a value, runs, and does not pollute the global variable space I am running in a function anonymous. var inside undefined: falsevar inside values: inside function 2 has a returned value, run, and the global variable space is not contaminated with I am running in a function anonymous. var inside undefined: falsevar inside values: inside function 3 has a returned value, run, and the global variable space is not contaminated with I am running in a naming function. var inside undefined: falsevar inside values: inside function 4 has a returned value. The definition is not run and the global variable space is not contaminated. I am running in a naming function. var inside undefined: falsevar inside values: inside global, all anonymous functions do not pollute the global variable space var inside undefined: truefunction foo undefined: truefunction bar undefined: false anonymous function 1 return value: 111 anonymous function 2 Return Value: 222 name function foo defined and called return value: 333 name function bar call return value: 444


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.