我在jsfiddle.net上玩,我很好奇为什么这会返回true?
if(0 < 5 < 3) {
alert("True");
}
Run Code Online (Sandbox Code Playgroud)
这样做:
if(0 < 5 < 2) {
alert("True");
}
Run Code Online (Sandbox Code Playgroud)
但这不是:
if(0 < 5 < 1) {
alert("True");
}
Run Code Online (Sandbox Code Playgroud)
这个怪癖是否有用?
为什么3>2>1返回false时1 < 2 < 3返回true?
console.log(1 < 2 < 3);
console.log(3 > 2 > 1);Run Code Online (Sandbox Code Playgroud)
我想问为什么
alert(3>2>1); // (1)
Run Code Online (Sandbox Code Playgroud)
在Javascript中返回FALSE.
我知道正确的是:
alert(3>2 && 2>1); // (2)
Run Code Online (Sandbox Code Playgroud)
但是代码1应该返回错误消息或者为TRUE!这个等式返回FALSE的具体原因是什么?
: 1 < 2 < 3
true
: 3 > 2 > 1
false
...
...
: 3 > 2 && 2 > 1
true
Run Code Online (Sandbox Code Playgroud)
也许我真的在思考问题,但我认为他们都会评价为真.为什么不呢?
javascript ×5
compare ×1
comparison ×1
console.log ×1
if-statement ×1
jquery ×1
node.js ×1
operators ×1
python ×1