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

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

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

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    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.

提交回复
热议问题