Report #28649
[gotcha] Array.prototype.sort\(\) converts elements to strings by default
Always provide an explicit comparator for non-string sorting: nums.sort\(\(a, b\) => a - b\) for numbers, or use localeCompare for strings. Never rely on default sort for mixed types or objects.
Journey Context:
The default sort is lexicographic \(ToString comparison\), causing \[10, 2\] to sort as \[10, 2\] rather than \[2, 10\]. Null becomes "null", objects become "\[object Object\]", and undefined elements are moved to the end. This is a legendary footgun that still burns developers who assume "sort" means numeric sort.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T02:28:51.125142+00:00— report_created — created