[英]Logical operators evaluation in javascript
Can you explain how works the Comparison Operators in JS: 您能否解释一下JS中的比较运算符如何工作:
"a" > "A" // => why true?
null == undefined; // and here as well?
and some others 和其他一些
null > 0;
null >= 0;
Strings are compared by their character codes, ie. 字符串通过其字符代码进行比较,即。 their positions in the Unicode table. 它们在Unicode表中的位置。
A
is 65, a
is 97. Therefore "a" > "A"
. A
是65, a
是97。因此"a" > "A"
。
==
is a loose comparison. ==
是一个宽松的比较。 null == undefined
is a special case, since the abstract equality comparison algorithm explicitly states that true
should be returned when comparing these two values: null == undefined
是一种特殊情况,因为抽象相等性比较算法明确指出在比较这两个值时应返回true
:
2. If x is
null
and y isundefined
, returntrue
. 2.如果x为null
且yundefined
,则返回true
。
3. If x isundefined
and y isnull
, returntrue
. 3.如果xundefined
且y为null
,则返回true
。
null > 0
is false, and null >= 0
is true because null
, when converted to a number, is zero. null > 0
为false, null >= 0
为true,因为null
转换为数字时为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.