Bitwise non-operators, a simple understanding is to change the symbol of the number of operations and subtract 1. Of course, this is just a simple understanding of converting data to the number type. For typeof var! = "Number" type, during the operation, it will try to convert to 32-bit integer data. If it cannot be converted to integer data, it will be converted to NaN;
Javascript in-place operations use a simpler method to implement this operation, so its implementation principle can be understood as follows:
The Code is as follows:
Var testData =-2.9;
Var testResult = (typeof testData = "number "&&! IsNaN (testData) & testData! = Infinity )? (TestData> 0 )? -Math. floor (testData)-1:-Math. ceil (testData)-1:-1;
First, if a data is converted to 32 integer data and the result is <0, it needs to be rounded up, for example,-2.9->-2. If> 0, for example, 2.6-> 2;
If a data cannot be converted to a 32-bit binary representation, it is converted to NaN, and then to-1. For example ~ {}/~ NaN =-1;
For example ~ Function () {return 100;}->-1;
In Jquery, such as if (!~ This. className. indexOf (str) {// do some thing .....}; Here, the returned value of this. className. indexOf (str) is either greater than-1 or equal to-1. When it is equal to-1 ,~ -1 = 0; then ,!~ -1 = true; then we can conclude that this does not contain the str class name ...;
For ~~ Operator. Similarly, it can also be expressed:
The Code is as follows:
Var testData = 2.1;
Var testResult = (typeof testData = "number "&&! IsNaN (testData) & testData! = Infinity )? (TestData> 0 )? Math. floor (testData): Math. ceil (testData): 0;
We also use the round-robin mode;