javascript - Why does !function foo(){} return false and !function foo(){}() return true?
女神的闺蜜爱上我
女神的闺蜜爱上我 2017-06-30 09:58:06
0
2
811

As mentioned, thank you!

女神的闺蜜爱上我
女神的闺蜜爱上我

reply all(2)
淡淡烟草味

The only ones judged as false in

js are the following:

  • 0

  • NaN

  • false

  • ''

  • null

  • undefined

Therefore:

!function foo () {} == !(function foo () {}) == false
!function foo(){}() == !(function foo () { return undefined })() == !undefined == true
小葫芦

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!

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template