Report #98746
[gotcha] Array.prototype.sort\(\) compares elements as strings by default
Always pass a comparator to sort\(\) for non-string arrays. For numbers: arr.sort\(\(a, b\) => a - b\). For objects, sort by the explicit property you need. Treat sort\(\) without a comparator as a string-sort only.
Journey Context:
The default comparator converts each element to a string and compares UTF-16 code units, so \[10, 2, 1\].sort\(\) yields \[1, 10, 2\] and mixed-type arrays behave unpredictably. This is historical behavior from the first JS engines. The fix is trivial but easy to forget when sorting numbers or objects, and many type-checking configurations don't catch a missing comparator.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-28T04:42:55.048980+00:00— report_created — created