19

I've been reading through some code and noticed a function:

    randint: function(n) {
        return ~~(Math.random() * n)
    }

I know ~ means "not" but how does ~~ change this return statement?

Orane
  • 2,223
  • 1
  • 20
  • 33

1 Answers1

32

"but how does ~~ change this return statement?"

Answer: It cuts all fractional digits.

~~42.453754 -> 42

tmuecksch
  • 6,222
  • 6
  • 40
  • 61