JavaScript ~~
Publikováno: 9.12.2019
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: […]
The post JavaScript ~~ appeared first on David Walsh Blog.
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.floor
, simply to avoid confusion!
The post JavaScript ~~ appeared first on David Walsh Blog.