gpt4 book ai didi

javascript - 两个javascript对象如何同时相等和不相等?

转载 作者:搜寻专家 更新时间:2023-11-01 05:21:35 24 4
gpt4 key购买 nike

下面是一个比较两个 JavaScript 对象的示例,但我对返回值感到困惑。

var i=new Object()
var j=new Object()

i==j假的

i!=j是的

i>=j是的

i<=j是的

i>j假的

i<j假的

如何确定上述值?我无法理解。

最佳答案

这是原因,

i==j false //Since both are referring two different objects

i!=j True //Since both are referring two different objects

i>=j true //For this, the both objects will be converted to primitive first,
//so i.ToPrimitive() >= j.ToPrimitive() which will be
//evaluated to "[object Object]" >= "[object Object]"
//That is why result here is true.

i<=j true //Similar to >= case

i>j false //Similar to >= case

i<j false //Similar to >= case

i<-j false //similar to >= case but before comparing "[object object]" will be negated
//and will become NaN. Comparing anything with NaN will be false
//as per the abstract equality comparison algorithm

你提到了 i<-j将被评估为 true .但这是错误的,它将被评估为 false .请参阅上述原因。

关于javascript - 两个javascript对象如何同时相等和不相等?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35680679/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com