What does console.log([1, 5, 10, 25, 100].sort()); output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-12.js
1console.log([1,5,10,25,100].sort());
Quirks
Answer & explanation
Console output
[ 1, 10, 100, 25, 5 ]
Why
Array.prototype.sort() with no comparator coerces every element to a string and sorts by UTF-16 code unit order, not numeric value. That's why '100' lands before '25' and '5' ends up last. To sort numbers correctly you must pass a comparator like (a, b) => a - b.