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')