Report #87
[gotcha] Array.prototype.sort\(\) default comparator sorts numbers as strings
Always provide a comparator when sorting numbers or mixed types: nums.sort\(\(a, b\) => a - b\) or Intl.Collator for strings. Never rely on the default sort for non-string data.
Journey Context:
The default comparator converts elements to strings and compares UTF-16 code units, so \[10, 2, 1\].sort\(\) becomes \[1, 10, 2\]. This is specified behavior \(ToString comparison\) but is almost never what developers want for numbers. The comparator callback is the only safe way to express intent. For non-ASCII strings, use localeCompare or Intl.Collator instead of the default sort to avoid surprising ordering.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-12T09:13:15.498820+00:00— report_created — created