Report #77063
[gotcha] Array.prototype.sort without comparator sorts lexicographically not numerically
Always provide an explicit comparator: use .sort\(\(a, b\) => a - b\) for numbers, and .sort\(\(a, b\) => a.localeCompare\(b\)\) for locale-aware strings.
Journey Context:
The spec defines default sort order as string conversion \(UTF-16 code units\) for consistency across types. This is legacy behavior from early JS implementations. Developers frequently forget this for numeric arrays, causing sorting bugs in data visualizations or financial tables where \[10, 2\] sorts to \[10, 2\]. Explicit comparators are required for correct numeric or locale-aware semantics.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:56:31.280415+00:00— report_created — created