What does console.log((2.5).toFixed(0), (3.5).toFixed(0)) output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-146.js
1console.log((2.5).toFixed(0),(3.5).toFixed(0))
Coercion
Answer & explanation
Console output
3 4
Why
Unlike banker’s rounding (round half to even), which would turn 2.5 into 2, toFixed rounds half away from zero for these exactly representable values, giving "3" and "4". Both 2.5 and 3.5 are exactly representable in binary, so no floating-point drift is involved here. The result is purely toFixed’s rounding rule.