Home  >  Q&A  >  body text

为什么0 == null 返会的是false?

0 >= null 返会的是true,而0 == null 返会的是false?

你的女神你的女神2875 days ago1245

reply all(3)I'll reply

  • 数据分析师

    数据分析师2017-09-30 22:39:12

    Why 0 == null returns false? -PHP Chinese website Q&A-Why 0 == null returns false? -PHP Chinese website Q&A

    Please watch and learn.

    reply
    0
  • 高洛峰
  • 欧阳克

    欧阳克2016-12-07 09:12:25

    js 比较运算符的算法,除了相等运算符号(==)和严格相等运算符(===),js 的比较运算符的规则:

    1、如果两个运算子都是字符串,则按照字典顺序比较

    2、否则,将两个运算子都转成数值,再进行比较

    而 js 的 null、undefined 与其他类型的值进行 == 比较时,结果都为 false;null == undefined 结果为 true

    相等运算符隐藏的类型转换,会带来一些违反直觉的结果。所以请尽量使用


    reply
    0
  • Cancelreply