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?
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?
"but how does ~~ change this return statement?"
Answer: It cuts all fractional digits.
~~42.453754
-> 42