I think your question can be changed to !(function foo(){}) returns false, !(function foo(){})() returns true? Because the code function foo(){}() will return Uncaught when executed SyntaxError: Unexpected token error.
The former is to negate the non-empty string. The Boolean value of the non-empty string is true. After negation, it is naturally false; The latter is to negate the return value of the self-executing function. The return value is undefined and converted into a Boolean value. is false, and its negation is true.
The above are personal opinions, welcome to discuss. Thanks!
The only ones judged as false in
js are the following:
0
NaN
false
''
null
undefined
Therefore:
I think your question can be changed to !(function foo(){}) returns false, !(function foo(){})() returns true?
Because the code function foo(){}() will return Uncaught when executed SyntaxError: Unexpected token error.
The former is to negate the non-empty string. The Boolean value of the non-empty string is true. After negation, it is naturally false;
The latter is to negate the return value of the self-executing function. The return value is undefined and converted into a Boolean value. is false, and its negation is true.
The above are personal opinions, welcome to discuss. Thanks!