开发者

JavaScript !!"false"

开发者 https://www.devze.com 2023-02-18 09:39 出处:网络
I expected !!\"false\" to return false i.e.开发者_如何学C !\"false\" would return true, so !!\"false\" would return \"false\", but when I tested it in the console, !!\"false\" returned true.

I expected !!"false" to return false i.e.开发者_如何学C !"false" would return true, so !!"false" would return "false", but when I tested it in the console, !!"false" returned true.

Why didn`t things happen as expected?


"false" is a non-empty string, which evaluates to true. Hence !"false" is false and !!"false" is true. You were probably thinking of !!false.


The reason this is occurring because anything other than an empty string will return true.

0

精彩评论

暂无评论...
验证码 换一张
取 消