Intl.Collator compares strings according to a locale and options. It serves a different purpose from simple character-code ordering for international lists and names containing digits. A zero result does not establish that the original strings are identical, and the comparison should not be transferred directly to identity or authorization checks.

Conceptual illustration of locale-aware sorting with numeric runs and accent or case sensitivity

Read the sign rather than the magnitude

ECMA-402 defines a negative result when the first string sorts before the second, a positive result when it sorts after, and zero when no relative order is distinguished. The actual number is implementation-defined. Do not require exactly -1 or 1: the sign and zero are the comparison contract.

Use a consistently configured collator for one list. Mixing locales or options during comparison makes the list's ordering rule difficult to explain. The magnitude of a nonzero result is not specified as a distance or similarity score.

Locales can define different base letters and orders

MDN compares German and Swedish ordering of ä. It sorts with a in the German example but after z in Swedish. There is no single alphabet order shared by every language. Match the chosen locale to the product's policy for the list shown to users.

Check supported languages and inspect the effective settings through resolvedOptions. A user-facing ordering and an internal key shared across systems may have different requirements. Locale-sensitive display comparison should not automatically become a universal stored-ordering rule.

Numeric collation is a string-comparison option

MDN's constructor reference illustrates numeric ordering with 1, 2, and 10. It may be useful for names such as item2 and item10. First decide whether the intended list uses this order or ordinary lexical ordering.

Numeric collation is not a general number parser or unit converter. It does not promise business-correct ordering for every combination of amounts, decimals, and version strings. Test actual names, and distinguish ordering an explicit numeric field from ordering its display text. This is a practical choice about the data model.

Expert perspective: sensitivity defines comparison equivalence

MDN and ECMA-402 explain that sensitivity controls which distinctions, including case and diacritics, affect comparison. Base sensitivity can treat variations of one base letter as equal for collation. Which characters share a base letter still depends on the locale.

In MDN's example, German ä and a compare as equal with base sensitivity, while Swedish distinguishes them. That equality does not mean byte-identical strings. Avoid using a display comparator alone to define account uniqueness or persistent identifiers. If equivalent items need an additional ordering rule, specify it separately.

Accent sensitivity distinguishes base letters and diacritics but not case. Case sensitivity distinguishes case while ignoring diacritic differences within the same base letter. Choose examples for the distinctions the product intends to retain rather than relying only on option names.

Distinguish sort usage from search usage

MDN advises callers using search to focus on whether a full-string comparison returns zero and not use its nonzero values for sorting. It does not mean substring search or every search function is implemented by this option. Use sort for list ordering and assess equality-style matching according to its intended policy.

Compare actual product names while varying locale, numeric, and sensitivity separately. Include exact matches, digit-containing names, and distinct originals that compare as equivalent. For example, two display-equivalent items can retain separate IDs for detail pages. Distinguishing order from identification avoids merging away data because a display comparator regards items as equivalent. The collator itself does not manage identifiers.

Intl.Collator is a locale-sensitive string comparator; display order, exact identity, and numeric business meaning need separate definitions to use its results correctly.

Sources