[英]JavaScript operator precedence and associativity
In JavaScript 在JavaScript中
var x = (5 >= 9 >= 0);
console.log(x);
// returns true
What is happening in that statement and what is the reason for that output? 该语句中发生了什么,输出的原因是什么?
The Operator precedence and Associativity chart explains what is happening. 运算符优先级和关联性图表说明了正在发生的事情。 The expression is evaluated in this order:
表达式按以下顺序求值:
/* 1 */ x = (5 >= 9) >= 0;
/* 2 */ x = false >= 0;
/* 3 */ x = true;
Explanation: 说明:
The true
statement, is understood as different from zero ... Consequently, false
is equals zero ... true
陈述应理解为不同于零 ...因此, false
等于零 ...
The statement: 该声明:
(5>=9>=0)
Turns into 变成
(false >= 0)
Since 5 is lower than 9. Then, if false is equal zero the result is true 由于5小于9。因此,如果false等于零,则结果为true
EDIT 编辑
As explained here ( All falsey values in JavaScript ), zero is among the falsy values in javascript... 如此处所述( JavaScript中的所有虚假值 ), JavaScript中的虚假值中有零...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.