Search code examples
javascriptoperators

what does ^= mean in js


I was on leetcode and I saw this symbol in the discuss section

var singleNumber = function(nums) {
    let result = 0;
    
    nums.forEach((num) => result ^= num)
    
    return result;
};

please please make me understand the solution leetcode solution


Solution

  • Bitwise XOR assignment (^=)

    The bitwise XOR assignment operator (^=) uses the binary representation of both operands, does a bitwise XOR operation on them and assigns the result to the variable.

    Source: MDN