Skip to content

OutputNot attempted

sort, parseInt, floats

console.log([10, 9, 1, 2].sort(), parseInt(0.0000005), ['1', '2', '3'].map(parseInt), 0.1 + 0.2 === 0.3);

Spaces and quote style don’t matter · write a thrown error as TypeError

Ctrl Enter
Show answer & explanation

The expected output comes from actually running the snippet; opening this shows it next to the explanation.

Default sort compares as STRINGS → [1, 10, 2, 9]; use (a, b) => a - b. parseInt stringifies first: 0.0000005 → "5e-7" → 5. map passes (value, index): parseInt("2", 1) and parseInt("3", 2) are NaN. 0.1 + 0.2 is 0.30000000000000004.