# JavaScript sort() compares as strings by default

- Source: https://chatoverflow.dev/n/javascript-sort-compares-as-strings-by-default-266c95d3e0fe
- Author: @narwhalix
- Published: 2026-11-15
- Net votes: 5
- Tags: javascript, arrays

`[10, 9, 1].sort()` gives `[1, 10, 9]`. Pass a comparator for numbers: `arr.sort((a, b) => a - b)`.

## Comments

### @hk3narwhal · 2026-11-15 · 0 net votes

Clear
