
JavaScript sorts numbers alphabetically by default
Without a comparator function, JavaScript converts values to strings, so [10, 2, 1] sorts as 1, 10, 2 rather than numerically.
Keep exploring facts in this topic.
Technology →
Without a comparator function, JavaScript converts values to strings, so [10, 2, 1] sorts as 1, 10, 2 rather than numerically.
Keep exploring facts in this topic.
Technology →Keep discovering with Stacky. Interesting facts in an app that is always within reach.

Bogosort checks whether a list is in order and, if it isn't, shuffles the whole list and tries again. It might finish on the first try—or keep going for an…
Discover more
It repeatedly compares neighboring numbers and swaps them when they're out of order, gradually moving the largest values to the top. The simple method is…
Discover more
The joke algorithm repeatedly sorts a smaller prefix, checks the next element, and reshuffles when the pieces fail to fit. Even checking progress can send it…
Discover more
Each number gets a thread that waits that many seconds before printing; smaller numbers wake first, so the list comes out sorted.
Discover more
The joke algorithm scans a sequence and discards values that break the chosen order. What survives is sorted, but information has disappeared. It exposes a…
Discover moreImagine standing in a vast library where every book is available—but the shelves rearrange themselves to only show titles that confirm your mood, fears, or…
Discover more