XOR(^) Bitwise Operator in JavaScript Last Updated : 23 Jul, 2025 Comments Improve Suggest changes Like Article Like Report In JavaScript, the bitwise XOR(^) Operator is used to compare two operands and return a new binary number which is 1 if both the bits in operators are different and 0 if both the bits in operands are the same. The operation is represented by the "^" symbol. This operator can be used to find the missing numbers in an array of natural numbers. Let's look at the truth table below to better understand the output of the XOR operation between two bits. ABOUTPUT ( A ^ B )000011101110Syntax: a ^ bExample 1: In this example, we will perform the XOR operation on a Number. JavaScript let a = 5; let b = 4; console.log(a^b); Output: 1Example 2: In this example, we will use the XOR operator to find missing the missing natural number in an array. JavaScript function getMissingNo(a, n) { let x1 = a[0]; let x2 = 1; for (let i = 1; i < n; i++) x1 = x1 ^ a[i]; for (let i = 2; i <= n + 1; i++) x2 = x2 ^ i; return x1 ^ x2; } let arr = [1, 2, 3, 5]; let N = arr.length; let missingNo = getMissingNo(arr, N); console.log(missingNo); Output: When we XOR two equal numbers they cancel each other. Here we find the XOR of all elements up to a length of the array and then XOR the natural numbers up to that length. When we XOR both the result together they do not cancel as one number is missing. The missing number is returned after the XOR operation. 4Supported Browsers: ChromeEdgeFirefoxOperaSafariWe have a complete list of JavaScript Bitwise Operators, to check those please go through, the JavaScript Bitwise Operators article Comment S shobhit_sharma Follow Improve S shobhit_sharma Follow Improve Article Tags : JavaScript Web Technologies Explore JavaScript BasicsIntroduction to JavaScript4 min readVariables and Datatypes in JavaScript6 min readJavaScript Operators5 min readControl Statements in JavaScript4 min readArray & StringJavaScript Arrays7 min readJavaScript Array Methods7 min readJavaScript Strings5 min readJavaScript String Methods9 min readFunction & ObjectFunctions in JavaScript5 min readJavaScript Function Expression3 min readFunction Overloading in JavaScript4 min readObjects in JavaScript4 min readJavaScript Object Constructors4 min readOOPObject Oriented Programming in JavaScript3 min readClasses and Objects in JavaScript4 min readWhat Are Access Modifiers In JavaScript ?5 min readJavaScript Constructor Method7 min readAsynchronous JavaScriptAsynchronous JavaScript2 min readJavaScript Callbacks4 min readJavaScript Promise4 min readEvent Loop in JavaScript4 min readAsync and Await in JavaScript2 min readException HandlingJavascript Error and Exceptional Handling6 min readJavaScript Errors Throw and Try to Catch2 min readHow to create custom errors in JavaScript ?2 min readJavaScript TypeError - Invalid Array.prototype.sort argument1 min readDOMHTML DOM (Document Object Model)9 min readHow to select DOM Elements in JavaScript ?3 min readJavaScript Custom Events4 min readJavaScript addEventListener() with Examples9 min readAdvanced TopicsClosure in JavaScript4 min readJavaScript Hoisting6 min readScope of Variables in JavaScript3 min readJavaScript Higher Order Functions7 min readDebugging in JavaScript4 min read Like