What is the meaning of ^= operator in JS

javascript, operators

Solution

`myVar ^= 5` is the same as `myVar = myVar ^ 5`. `^` is the bitwise `xor` operator

Let's say `myVar` was set to 2

- 5 in binary is: 101

- 2 in binary is: 010

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.

Thus 111 which converted back to decimal is 7

So `5^2` is 7

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

Problem

I am trying to figure out this operator on JS - ``` 'string' ^= 'string'; ``` But I can not find ant information. Is that a comparison or assignment ? Thanks.

Original source

Related problems