爲什麼null> 3 false並且爲空< 3在節點中是否爲true?爲什麼null> 3 false並且null <3 true在節點中?
$ node
> null > 3
false
> null < 3
true
爲什麼null> 3 false並且爲空< 3在節點中是否爲true?爲什麼null> 3 false並且null <3 true在節點中?
$ node
> null > 3
false
> null < 3
true
因爲它脅迫null
到0
施加更少/比運營商帶來更大時。
Section 11.8.5 of the spec表明<
和>
運營商將調用ToNumber
左側值(null
)。
Section 9.3 of the spec顯示ToNumber
會將null
翻譯爲0
。
我不是100%確定,但它看起來像空使用比較器時爲0,但奇數空== 0和空=== 0返回false但空< = 0當空< 0返回false時返回true。
> null == 0
false
> null === 0
false
> null <= 0
true
> null < 0
false
> null < -1
false