Language Implementations

What Algorithm Does JavaScript Array.sort() Use?

Updated June 8, 2026 5 min read

Array.prototype.sort() is one of the most-used methods in JavaScript, but its behavior has evolved and varies by engine. Here is what actually runs when you call it, and the one rule that saves you from the most common bug.

The engine implementations

V8 (Chrome, Node.js) switched to Tim Sort in 2018. Firefox's SpiderMonkey uses a Merge Sort variant. The ECMAScript spec does not mandate an algorithm, but since ES2019 it requires the sort to be stable, so all modern engines preserve the order of equal elements.

The numeric gotcha

The default sort compares elements as strings, so [10, 9, 100].sort() gives [10, 100, 9]. Always pass a comparator for numbers: arr.sort((a, b) => a - b). See more JS examples in sorting algorithms in JavaScript.

Frequently asked questions

Is JavaScript's Array.sort stable? +
Yes, since ES2019 the specification requires Array.sort to be stable, so equal elements keep their original order across all modern engines.
What algorithm does V8 use for sorting? +
Since 2018, V8 (used by Chrome and Node.js) implements Array.prototype.sort with Tim Sort, a stable hybrid of Merge and Insertion Sort.

See it in motion

Watch this algorithm and 9 others run step by step in our free interactive visualizer.

▶ Launch Visualiser

Related articles

← Back to all articles