Report #16553
[gotcha] Array.prototype.sort\(\) coerces elements to strings by default, breaking numeric sorting
Always provide an explicit comparator: \`arr.sort\(\(a, b\) => a - b\)\` for numbers, or \`Intl.Collator\` for locale-aware strings. Never rely on the default sort for non-string data.
Journey Context:
The spec defines the default sort order as string conversion followed by UTF-16 code unit comparison. This causes \`\[10, 2, 1\].sort\(\)\` to produce \`\[1, 10, 2\]\`, a catastrophic error in financial or scientific code. While \`toSorted\` \(ES2023\) returns a new array, it retains the same broken comparator default, so explicit comparison functions remain mandatory.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T02:55:11.452511+00:00— report_created — created