Javascript equals比较运算符在连续使用四次后给出错误结果
我有一个带有getter方法的类Square来确定Square是否有效。如果我的方块有1的边,我的代码将返回true。如果我的正方形有5的4条边,则返回false。有人能解释发生了什么事吗 如您所见,我在浏览器中访问了此项,并获得了以下结果: 表情Javascript equals比较运算符在连续使用四次后给出错误结果,javascript,comparison-operators,Javascript,Comparison Operators,我有一个带有getter方法的类Square来确定Square是否有效。如果我的方块有1的边,我的代码将返回true。如果我的正方形有5的4条边,则返回false。有人能解释发生了什么事吗 如您所见,我在浏览器中访问了此项,并获得了以下结果: 表情 testArray[0] == testArray[1] == testArray[2] == testArray[3] 从左到右执行=3次 ((testArray[0] == testArray[1]) == testArray[2]) ==
testArray[0] == testArray[1] == testArray[2] == testArray[3]
从左到右执行=
3次
((testArray[0] == testArray[1]) == testArray[2]) == testArray[3]
第一次,当数组项相等时,第一次将计算为true
:
((testArray[0] == testArray[1]) == testArray[2]) == testArray[3]
(true == testArray[2]) == testArray[3]
如果项目为数字,则下一次比较仅在项目为1时返回true
:
console.log(true==1);
console.log(true==2);
console.log(true==5)代码>表达式
testArray[0] == testArray[1] == testArray[2] == testArray[3]
从左到右执行=
3次
((testArray[0] == testArray[1]) == testArray[2]) == testArray[3]
第一次,当数组项相等时,第一次将计算为true
:
((testArray[0] == testArray[1]) == testArray[2]) == testArray[3]
(true == testArray[2]) == testArray[3]
如果项目为数字,则下一次比较仅在项目为1时返回true
:
console.log(true==1);
console.log(true==2);
console.log(true==5)代码>请参阅:请参阅: