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);
source
share