【发布时间】:2021-08-05 13:36:51
【问题描述】:
我在下面有这 2 个例子 -
console.log("a" > "3") // 输出为真
console.log("hello" > "3") // 输出为真
根据MDN、If both values are strings, they are compared as strings, based on the values of the Unicode code points they contain。
但随后他们在下一段中也写了以下内容,Strings are converted based on the values they contain, and are converted as NaN if they do not contain numeric values.
按照这个逻辑,不应该两个语句都是false,因为无论是什么运算符,“a”和“hello”都是字符串中的单词,它们没有数值,因此,它应该返回NaN,而NaN为假;因此,只要其中一个操作数是false,它就会输出false?
如果我需要坚持上面的前一条陈述,你能帮我看看这个逻辑吗?
谢谢。
【问题讨论】:
-
我是JS新手,对细节超级细致,请不要对我评价太苛刻..
标签: javascript comparison-operators