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