Report #91391
[gotcha] Array.prototype.sort without comparator coerces numbers to strings lexicographically
Always provide an explicit comparator function: use \(a, b\) => a - b for numeric sorting, or localeCompare for locale-aware string sorting. Never rely on default sort for mixed types or numbers.
Journey Context:
ECMA-262 specifies that Array.prototype.sort converts elements to strings \(via toString\) and compares UTF-16 code unit values if no comparator is provided. This causes \[10, 2\].sort\(\) to yield \[10, 2\] because '10' < '2' lexicographically. While ES2019 guaranteed stability, the string coercion remains. This is a legacy behavior that cannot be changed for web compatibility.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T11:59:36.529283+00:00— report_created — created