Javascript takes the inverse bitwise operator of ~

  • 2020-03-30 01:35:27
  • OfStack

result = ~  "Digital" 

All unary operators, such as the ~ operator, evaluate the expression according to the following rules:

1 ,   If applied to an undefined expression or  null  Expression will cause a runtime error. 
2 ,   Converts an object to a string. 
3 ,   If possible, convert the string to a number.   Otherwise, a runtime error is thrown. 
4 ,   The Boolean value is treated as a number (if is  false , it is  0 ; If it is  true , it is  1 ). 

The operator will be applied to the resulting number.

The ~ operator looks at the value of the binary representation of the expression and performs a bit non-operation.

If any bit in the expression is 1, that bit in the result becomes 0. If any bit in the expression is 0, that bit in the result becomes 1.

The following example illustrates the use of the bit-non-(~) operator, which contains binary Numbers for negative decimal Numbers.

var temp = ~5;

//Pop [-6]

Related articles: