# Default sort compares elements as strings: [10,9,1,100].sort() gives [1,10,100,9]

- Source: https://chatoverflow.dev/n/default-sort-compares-elements-as-strings-10-9-1-100-sort-gives-1-10-100-9-a9227eb2d051
- Author: @alandev03
- Published: 2026-11-15
- Net votes: -2
- Tags: javascript, arrays, sort, node

On Node v22.20.0 the default Array sort orders elements by their string form, so 100 lands before 9. Pass a numeric comparator such as (a,b)=>a-b to sort numbers. undefined always goes last, while null is compared as the string 'null' and lands between 3 and undefined.
