JavaScript is loaded with tiny syntax tricks to accomplish useful effects. For example, explore any codebase to see !! being used to convert a value to a boolean value. Have you seen ~~ before? Let’s have a look at what it does!
We can employ ~~ to trigger a Math.floor operation with those special characters:
~~9.1 // 9 ~~9.99 // 9 ~~0.01 // 0
It’s interesting that JavaScript uses ~~ to alias Math.floor, but I’d much prefer devs I work with use the text Math.
from Proven Ways https://ift.tt/354OjhO
Comments
Post a Comment