JavaScritp犀牛书有错误? null === null 书上说不相等。

(美)David Flanagan. JavaScript权威指南(原书第6版) (Kindle 位置 1682-1684). Kindle 版本.

严格相等运算符“===”首先计算其操作数的值,然后比较这两个值,比较过程没有任何类型转换: ·如果两个值类型不相同,则它们不相等。 ·如果两个值都是null或者都是undefined,则它们不相等。

我的理解
null === null ,应该返回 true。

在Chrome中实验
代码
console.log(" undefined === undefined, is that true? " + (undefined === undefined));
console.log(" null === null, is that true? " + (null === null));

返回结果
undefined === undefined, is that true? true
null === null, is that true? true

请问是书上写错了?

阅读 3.6k
4 个回答

翻译错误。
图片描述

我觉得是不是你的书的问题……
我给你摘抄一段:

The strict equality operator === evaluates its operands, and then compares the two
values as follows, performing no type conversion:

  • If the two values have different types, they are not equal.

  • If both values are null or both values are undefined, they are equal.

  • If both values are the boolean value true or both are the boolean value false, they are equal.

...

第二条是说的相等的

新手上路,请多包涵
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题