The Javascript bitwise negation operator (~) performs a bitwise non-negation operation on an expression. such as ~ =-2; ~2 =-3; ~99 =-100
The code is as follows: result = ~ "number" all unary operators, such as the ~ operator, evaluate the value of an expression according to the following rules: The code is as follows: 1, if applied to an undefined expression or null expression, a run-time error is raised. 2, convert the object to a string. 3, if possible, converts a string to a number. Otherwise, a run-time error is raised. 4, the Boolean value is treated as a number (if False, 0, or 1 if true). Operator will be applied to the result number. The ~ operator looks at the value of the binary representation of the expression and performs a bitwise NON operation. If any one in the expression is 1, the bit in the result becomes 0. If any one in the expression is 0, the bit in the result becomes 1. The following example illustrates the use of the bitwise NON (~) operator, which contains a binary that represents a decimal number, and if you are unfamiliar with this, read the decimal negative conversion to binary, octal, hex. The code is as follows: var temp = ~5; /* 52 in 101, fill 32-bit 00000000000000000000000000000101-bit counter 11111111111111111111111111111010 because 32 bit the first is 1, so this is a negative number, Convert binary to negative, you need to reverse code 00000000000000000000000000000101, and then +1 00000000000000000000000000000110 to decimal 6, plus the symbol into a negative number-6 * * Alert (temp); Pop-up "-6"