Report #10858
[gotcha] Array.prototype.sort\(\) sorts numbers lexicographically by default
Always provide an explicit comparator for numeric arrays: arr.sort\(\(a, b\) => a - b\). For extreme ranges where subtraction might overflow, use \(a > b ? 1 : -1\)
Journey Context:
The spec converts elements to strings via ToString and compares UTF-16 code units, a legacy optimization for string sorting. This is a breaking change risk to alter now. Developers intuitively expect numeric order because it is the common case. The \(a - b\) pattern is concise but risks numeric overflow with very large integers \(rare\); the ternary form is overflow-safe but slower. Linting for 'sort-without-compare' catches this.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:49:36.632606+00:00— report_created — created