开发者社区> 问答> 正文

javascript 中 字符串 0 '0' 的布尔值

'0'==false;//true

'0'||1;//'0'

'0'?true:false;//true

内部到底有什么不同?

展开
收起
a123456678 2016-07-15 11:30:39 2304 0
1 条回答
写回答
取消 提交回答
  • 找到答案了:http://ecma262-5.com/ELS5_HTML.htm#Section_11.9.3

    11.9.3 The Abstract Equality Comparison Algorithm

    The comparison x == y , where x and y are values, produces true or false . Such a comparison is performed as follows:
    If Type(x) is the same as Type(y), then
    If Type(x) is Undefined, return true.
    If Type(x) is Null, return true.
    If Type(x) is Number, then
    If x is NaN, return false.
    If y is NaN, return false.
    If x is the same Number value as y, return true.
    If x is + and y is −, return true.
    If x is − and y is +, return true.
    Return false.
    If Type(x) is String, then return true if x and y are exactly the same sequence of characters (same length and same characters in corresponding positions). Otherwise, return false.
    If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false.
    Return true if x and y refer to the same object. Otherwise, return false.
    If x is null and y is undefined, return true.
    If x is undefined and y is null, return true.
    If Type(x) is Number and Type(y) is String, return the result of the comparison x == ToNumber(y).
    If Type(x) is String and Type(y) is Number, return the result of the comparison ToNumber(x) == y.
    If Type(x) is Boolean, return the result of the comparison ToNumber(x) == y.
    If Type(y) is Boolean, return the result of the comparison x == ToNumber(y).
    If Type(x) is either String or Number and Type(y) is Object, return the result of the comparison x == ToPrimitive(y).

    2019-07-17 19:56:49
    赞同 展开评论 打赏
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
JavaScript异步编程 立即下载
Delivering Javascript to World 立即下载
编程语言如何演化-以JS的private为例 立即下载