whatstheoutput_

#20: 5.9 | 0

Topic: numbers · Difficulty: ★

console.log(5.9 | 0);

Output

5

Why

Bitwise operators like | only exist for 32-bit signed integers, so before the operation runs, JavaScript converts each operand with ToInt32 — which truncates any fractional part toward zero (not rounding) and drops bits beyond 32. 5.9 truncates to 5, and 5 | 0 (ORing with all-zero bits) leaves it unchanged, so the result is 5. This truncate-to-integer side effect is why `x | 0` was a common old-school trick for flooring positive numbers before Math.trunc existed.

More numbers puzzles

Play today's puzzle →