foo relative to function expression ' var foo = function () { /* code */ function () { code */} (); // syntaxerror:unexpected token ( it treats it as a function without a name and throws an error because the declaration of functions requires a name.
varFoo =function() {Console.log (1)} (), the answer is yes. //However, the function declaration is syntactically invalid, it is still a declaration, and the enclosing parenthesis is invalid because the parentheses need to contain an expression.
If you want to call an anonymous function directly, you need to let JS parse it according to the expression.functionFoo () {/*Code*/}();//syntaxerror:unexpected Token//now, you put an expression in parentheses without throwing an error ..., but the function is not executed because:functionFoo () {/*Code*/} (1)//it is equivalent to the following, a function declaration followed by an expression that is completely non-relational:functionFoo () {/*Code*/}(1);
when parentheses wrap a function, it parses the function as an expression by default, not the function declaration. (function () {/* code */} ()); // Crockford recommends this one, the expression inside the parentheses represents the function call expression immediately (function () {/* code */}) (); // but this one works just as well, the expression in parentheses represents the function expression