We already know that there are lots of ways of rounding in JS. But did you know that there's a shorthand for
If we use the Bitwise Operator
~ twice, we can floor a number.
let num = 1.13542345; console.log(~~num); // returns 1
No, I dont really understand how it works either. It's probably not a great thing to write in your code, because other people might not understand it either. But in case you do come across it, now you know what it means.
If you enjoyed this article, sign up here to get new articles whisked straight to your inbox!