Report #104747
[gotcha] Array.sort\(\) without a comparator converts elements to strings and sorts lexicographically, producing \[1, 10, 2\] instead of \[1, 2, 10\]
Always provide a comparator function: arr.sort\(\(a, b\) => a - b\) for numbers, or use localeCompare for strings with correct order. Do not rely on the default sort unless you specifically need string-based ordering.
Journey Context:
The default sort order is built upon converting each element to a string and comparing UTF-16 code units. This is a classic footgun because it silently produces wrong numeric order. Many codebases write arr.sort\(\) assuming it works like a stable, numeric sort. The fix is trivial but the surprise is that the error is silent — no warnings, no hints. Modern V8 introduced a stable sort in ES2019, but stability doesn't fix the string coercion issue.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-10-11T20:06:42.344449+00:00— report_created — created