Why does 'Mystery!' <= 'Z' equal true but 'the' <= 'Z' equal false but both
'Mystery!' >= 'A' and 'the' >= 'A' equal true. How does such comparision work?
2 Answers
it's comparing the UTF-16 code for the string value. Try the same comparisons with charCodeAt method to understand what's happening here
'y'.charCodeAt() <= 'Z'.charCodeAt()
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/charCodeAt
Comments
Upper case letters before lower case letters.
M = ascii value 77
Z = 90
77 < 90
t = 116
Z = 90
116 !< 90
See more here: www.asciitable.com
1 Comment
Tom Blodget
JavaScript doesn't use ASCII for built-in text datatypes. I'm not aware of any language that does.
'B' < 'a'. Characters are usually (on most systems) in this order:..., A, B, ..., Z, ... , a, b, c, ...