Bitwise non-operators, the simple understanding is to change the number of operands and subtract 1, of course, it is simply a simple understanding of the data can be converted to type numbers.
Then, for the type of typeof var!== "number", when the operation is performed, it will attempt to convert to 32-bit shaping data, and if it cannot be converted into the shaping data, it will be converted to Nan;
JS is a more convenient way to implement this operation in the bitwise operation, then its implementation principle can be understood in general:
var testdata=-2.9var testresult= (typeof
First, if a data is <0 when it tries to convert to 32 shaping data, it needs to be rounded up, such as -2.9->-2, if >0, rounding it down, such as: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;
Another example is ~function () {return 100;} ->-1;
In jquery, useful for example if (!~this.classname.indexof (str)) {//do some thing ...}; Here, for the return value of This.className.indexOf (str), it is either greater than-1, or equal to 1, at the time it equals-1, ~-1===0; then,!~-1===true; Then you can conclude that this does not include the class name Str ... ;
For the ~ ~ operator, in the same vein, it can also be expressed as:
var testdata=2.1var testresult= (typeof
The same way the upper and lower rounding is used to understand;
The understanding analysis of JS bitwise non (~) operator and ~ ~ operator