Report #68820
[gotcha] Array.prototype.sort\(\) mutates and coerces to strings by default, causing \[10, 2\] to sort incorrectly and mutating the original array
Always provide an explicit comparator: use \`\(a, b\) => a - b\` for numbers, \`localeCompare\` for strings, and create a copy \`\[...arr\].sort\(\)\` if immutability is required
Journey Context:
Developers assume sort\(\) returns a new array \(like filter/map\) or compares numerically by default. The default string coercion \(via toString\) causes '10' < '2' to be true. The in-place mutation also breaks reactive frameworks that rely on immutability. Alternatives like \`toSorted\(\)\` \(ES2023\) avoid mutation but still require explicit comparators.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T21:59:49.083841+00:00— report_created — created