字符串与字符串的比较

棋手

我在下面得到了这两个例子 -

console.log("a" > "3") // 输出真

console.log("hello" > "3") // 输出真

根据MDNIf 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?

如果我需要坚持上面的前一个陈述,请您帮我解释一下这个逻辑吗?

谢谢。

福克斯代码

您正在比较两个字符串(在引号中),而不是将字符串与数字进行比较。这应该回答你的问题:

"a" > "3" //true
"a" > 3 //false

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章