Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to deal with double wavy lines in javascript?
How to deal with double wavy lines in javascript?
The function of wavy line operator "~" in js is to convert a number into a signed 32-bit integer and do bit inversion, which means to convert a number into two's complement and then invert 0 and 1. Reversing a number twice will turn it into the original number, so the function of the double wavy line is to convert a decimal point into an integer. When the number is very small, it can be regarded as a lazy way to write Math.floor, and it will not overflow when converted into a 32-bit integer. However, the more general mathematical writing. Floor is "num | 0", that is, bit or 0, which will not change the number in bit operation but can be quickly converted into an integer, and bit or 0 is the fastest way to convert a number into an integer.