Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
64
rated 0 times [  70] [ 6]  / answers: 1 / hits: 22115  / 8 Years ago, thu, september 22, 2016, 12:00:00

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?


More From » javascript

 Answers
4

but how does ~~ change this return statement?



Answer: It cuts all fractional digits.



~~42.453754 -> 42


[#60630] Wednesday, September 21, 2016, 8 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
aileent

Total Points: 556
Total Questions: 107
Total Answers: 101

Location: Croatia
Member since Fri, Sep 11, 2020
4 Years ago
;