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

Time:10-12

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.

And

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

CodePudding user response:

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

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

  • Related