javascript - 为什么 'false' 在 javascript 中是真实的?

标签 javascript casting boolean truthiness

我知道空字符串在 javascript 中是假的,非空字符串在 javascript 中是真。

但是,为什么 'false' 在 javascript 中是真实的,规范中是否有任何明确的内容?这是性能问题还是在某些情况下您希望字符串 'false' 代表 true

最佳答案

is there anything explicit in the specification?

Yes :

The result is false if the argument is the empty String (its length is zero); otherwise the result is true.

关于javascript - 为什么 'false' 在 javascript 中是真实的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32720503/

相关文章:

java - 我的正则表达式与某个输入不匹配 - java

javascript - JSONP 请求中可以提交的内容是否有限制?

Javascript/html : How to generate random number between number A and number B?

c++ - 同时转换位宽和有符号/无符号,首先执行哪个转换?

android - 将 Object[] 转换为 ContentValues[] 时出错

php - 反向 boolean 求值

java - 从另一个类调用非静态 void

javascript - 如何在面板中调用其他 JS 文件的函数和变量 - Chrome 扩展

javascript - 在 JavaScript 对象中定义函数的简写

c# - 我想要 "(int)null"返回我 0