14

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,109
  • 1
  • 19
  • 31

1 Answers1

25

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

Answer: It cuts all fractional digits.

~~42.453754 -> 42

tmuecksch
  • 5,535
  • 5
  • 36
  • 57