Report #4307
[gotcha] Array.prototype.sort mutates in-place and coerces elements to strings by default
Always provide an explicit comparator function; use toSorted\(\) for immutable sorting. Never assume numeric sort without \(a, b\) => a - b.
Journey Context:
Developers often assume sort\(\) returns a new array or sorts numbers numerically. In reality, it mutates the original array and converts elements to UTF-16 strings. This causes silent bugs with numbers \(10 sorts before 2\) and breaks React/Redux immutability expectations. The toSorted method \(ES2023\) provides immutable alternatives but has limited browser support requiring polyfills.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T19:11:59.787842+00:00— report_created — created