admin管理员组文章数量:1336645
I expected !!"false" to return false i.e. !"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?
I expected !!"false" to return false i.e. !"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?
Share Improve this question edited Mar 18, 2011 at 4:57 mjmitche asked Mar 18, 2011 at 4:39 mjmitchemjmitche 2,0676 gold badges25 silver badges31 bronze badges 1- Possible duplicate of How can I convert a string to boolean in JavaScript?. Voted to close. – MAK Commented Mar 18, 2011 at 4:42
2 Answers
Reset to default 12"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.
本文标签: JavaScript quotfalsequotStack Overflow
版权声明:本文标题:JavaScript !!"false" - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742242793a2438937.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论