DEV Community

Discussion on: A neat little trick with JavaScript's indexOf()

Collapse
 
jonrandy profile image
Jon Randy 🎖️

~~ can be used instead of Math.floor and is actually (I believe) faster

Collapse
 
werninator profile image
Patrick Werner

Oh nice! I didn't know that, cool :o

Collapse
 
rcfox profile image
Ryan Fox

~~ truncates, which rounds towards 0. Math.floor rounds towards -∞.

> ~~(-1.2)
-1
> Math.floor(-1.2)
-2
Collapse
 
jonrandy profile image
Jon Randy 🎖️

Yup, I should have added that small caveat