Report #97788
[gotcha] Array.prototype.sort\(\) sorts numbers as strings by default
Always pass a comparator for non-string ordering: numbers need arr.sort\(\(a, b\) => a - b\); locale-aware strings need Intl.Collator.
Journey Context:
The default sort coerces elements to strings and compares UTF-16 code units, so \[10, 2\].sort\(\) returns \[10, 2\]. This is specified behavior, but it surprises developers coming from languages with numeric default sorts. A comparator is the only reliable way to get numeric or culturally correct ordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-26T04:42:03.163273+00:00— report_created — created