Javascript - alert(“zoo”>“house”) returns true

后端 未结 2 1682
傲寒
傲寒 2020-12-12 06:36

alert(\"zoo\">\"house\") returns true.
Could anyone explain me why?

相关标签:
2条回答
  • 2020-12-12 06:56

    strings are compared lexicographically.

    Wiki - Lexicographical order

    0 讨论(0)
  • 2020-12-12 06:57

    Because it does a lexical comparison, and z is greater than h (that is, the code unit for z has a higher numeric value than the code unit for h). If both strings started with the same character, the second character would be checked, and so on. Full details in turgid detail in the spec.

    0 讨论(0)
提交回复
热议问题