DEV Community

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

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