Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is 'Ö'.localeCompare('Z') equal -1 instead of 1, if 'Ö' > 'Z'?

Why console.log('Ö'.localeCompare('Z')); //-1 ?

If

"str.localeCompare(str2):
Returns a negative number if str is less than str2.
Returns a positive number if str is greater than str2.
Returns 0 if they are equivalent.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

And

console.log('Ö' > 'Z'); // true

>Solution :

'Ö' > 'Z' compares charcodes (indeed, 214 > 90)

localeCompare compares alphabetically (in most alphabets, ‘Ö’ precedes ‘Z’)

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading