1

I use Math.random() * 10 to get a number between 0 and 10. However, when I use that with disjunction (|), the returned value becomes an integer even though I do not use such methods as Math.floor().

let n = Math.random() * 10;
// n is very likely a decimal number.

let n = Math.random() * 10 | 20;
// n becomes an integer.
kchui
  • 13
  • 4

1 Answers1

1

| is the bitwise OR operator and when applied to numbers, it first converts both operands to 32-bit integers.

Unmitigated
  • 76,500
  • 11
  • 62
  • 80