为什么(0 <5 <3)返回true? [英] Why does (0 < 5 < 3) return true?
本文介绍了为什么(0 <5 <3)返回true?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在jsfiddle.net玩,我很好奇为什么这会返回true?
I was playing around in jsfiddle.net and I'm curious as to why this returns true?
if(0 < 5 < 3) {
alert("True");
}
这样做:
if(0 < 5 < 2) {
alert("True");
}
但这不会:
if(0 < 5 < 1) {
alert("True");
}
这个怪诞有用吗?
推荐答案
操作顺序导致(0 <5 <3)
在javascript中解释为((0 <5)<3)
,其产生(true <3)
,true被计为1,它返回true。
Order of operations causes (0 < 5 < 3)
to be interpreted in javascript as ((0 < 5) < 3)
which produces (true < 3)
and true is counted as 1, causing it to return true.
这也是为什么(0 <5 <1)
返回false, code>(0 <5)返回true,解释为 1
,结果为 < 1)
。
This is also why (0 < 5 < 1)
returns false, (0 < 5)
returns true, which is interpreted as 1
, resulting in (1 < 1)
.
这篇关于为什么(0 <5 <3)返回true?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文