Report #11074
[gotcha] Array.prototype.sort\(\) mutates in-place and coerces elements to strings by default
Always provide a comparator function \(a, b\) => a - b for numbers; use toSorted\(\) for immutability
Journey Context:
Developers often assume sort\(\) returns a new array like map/filter, but it mutates the original. Additionally, \[1, 11, 2\].sort\(\) yields \[1, 11, 2\] because elements are converted to strings. This causes subtle bugs in data tables and numeric arrays.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:22:50.949628+00:00— report_created — created