Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/google-app-engine/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript equals比较运算符在连续使用四次后给出错误结果_Javascript_Comparison Operators - Fatal编程技术网

Javascript equals比较运算符在连续使用四次后给出错误结果

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]) ==

我有一个带有getter方法的类Square来确定Square是否有效。如果我的方块有1的边,我的代码将返回true。如果我的正方形有5的4条边,则返回false。有人能解释发生了什么事吗

如您所见,我在浏览器中访问了此项,并获得了以下结果:

表情

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)请参阅:请参阅: