What does the caret character (^) do in JavaScript?

I thought Math.pow(2,2) is 2^2 , but that is not the case. So what does ^ (caret) mean in JavaScript?

I ran some tests in the console but did not recognize the results:

 2 ^ 2 = 0 2 ^ 3 = 1 1 ^ 2 = 3 
+7
source share
5 answers

This means bitwise XOR .

+9
source

This is a bitwise integer XOR operation ( MDC reference ).

+3
source

Operator ^ bitwise XOR, you have more information in MDN: https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators

+2
source

This statement performs a logical XOR operation. (the out bit is 1 when both input bits are different).

+2
source

This is a bitwise XOR operator that returns one for each position, where one (not both) of the corresponding bits of its operands is one. The following example returns 4 (0100):

 Code: result = a ^ b; 
+1
source

All Articles