What is the meaning of ^ = operator in JS

I am trying to figure out this operator in JS -

'string' ^= 'string';

But I can not find ant information. Is this a comparison or purpose?

Thank.

+5
source share
4 answers

myVar ^= 5matches with myVar = myVar ^ 5. ^- bitwise operatorxor

Let's say it myVarwas set to 2

  • 5 in binary format: 101
  • 2 in binary format: 010

An exclusive "or" checks the first bit of both numbers and sees 1.0 and returns 1, then sees 0.1 and returns 1 and sees 1.0 and returns 1.

So 111 converted back to decimal is 7

So 5^2is 7

var myVar = 2;
myVar ^= 5;
alert(myVar); // 7
+7
source

^ (caret) - XOR ( ). , +=, a ^= b a = a^b.

. Javascript Mozilla.

+4

x ^= y XOR x = x^y - "", . , , "^" XOR.

+2

'' ( ), - XOR. , :

"XOR" "eXclusive OR". ? :

11000110 -- random byte
10010100
--------- ^ -- XOR
01010010

XOR is a bitwise operation that returns two if one of the two bits is 1 and the other is 0. If they are both 1, it is not, not exclusive or (normal or allow two 1s) .

+1
source