LocaleCompare () lines containing "1" and "-1" in different browsers

I noticed the following differences in return values ​​when comparing strings containing "-1", "1"and "0"using String.prototype.localeCompare()in Chrome and Edge:

"1".localeCompare("-1");
// Edge: -1, Chrome: 1

"0".localeCompare("-1")
// Edge: -1, Chrome: 1

"-1".localeCompare("1")
// Edge: 1, Chrome: -1
  • Why is there a difference in return values ​​between browsers?
  • Is there a way for browsers to consistently follow in the scripts above?
+4
source share

Source: https://habr.com/ru/post/1670916/


All Articles