有在ECMAScript Language Specification 11.9.1 等于运算符 (==):
NOTE 3 The equality operator is not always transitive. For example, there might be two distinct String objects, each representing the same String value; each String object would be considered equal to the String value by the == operator, but the two String objects would not be equal to each other. For Example:
new String("a") == "a"
and"a" == new String("a")
are both true.new String("a") == new String("a")
is false.
但在11.9.6 严格相等比较算法中:
7. Return true if
x
andy
refer to the same object. Otherwise, return false.
但是没有,用jsc
new String("a")===new String("a")
是真的。
那是 jsc.exe 错误吗?或者它们是同一个对象?为什么?
最佳答案
js中的运算符===如果类型相等且值相等则返回true。所以它返回 true 是正确的,因为它们都是 String 对象并且它们的值是“a”。
关于新 String ("a") 对象的 JavaScript(严格)相等,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23847475/