CKTIS / JavaScript
Bitwise XOR operator (^)
The ^ operator performs bitwise exclusive OR: a result bit is 1 when the corresponding operand bits differ. It supports Number and BigInt, but does not allow those numeric types to be mixed.
Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support
Syntax
left ^ rightThe left ^ right operator compares corresponding bits: 0 ^ 0 and 1 ^ 1 produce 0, while 0 ^ 1 and 1 ^ 0 produce 1. It does not mean exponentiation — use ** for that. It is not a logical operator returning a Boolean either.
Operands undergo numeric conversion. For Number, both are converted to signed 32-bit integers, and the result is also in that range. Fractional parts are discarded toward zero, and values wrap to 32 bits; NaN and infinities become zero. Consequently, 4294967296 ^ 0 produces 0: ^ 0 is not a safe way to preserve an arbitrary number.
For two BigInt values, the result is a BigInt, without 32-bit truncation. Negative values behave as two's-complement representations with unlimited sign extension. After conversion, both operands must have the same numeric type; 10n ^ 6 throws a TypeError.
An XOR mask toggles bits wherever it contains 1 and preserves the others. In the example, 1010 XOR 0110 produces 1100, or 12; applying the same mask again restores 10. Calling String ensures consistent console formatting of the BigInt result.
Examples
const flags = 0b1010;
const mask = 0b0110;
const toggled = flags ^ mask;
console.log(toggled);
console.log(toggled ^ mask);
console.log(String(10n ^ 6n));
console.log(4294967296 ^ 0);Result
12 10 12 0
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.