Solution – 1 – Using Arithmetic Operators
function swapNumb(a, b){
console.log('Before swap Output: ','a: ', a, 'b: ', b);
b = b -a;
a = a+ b;
b = a-b;
console.log('After swap Output: ','a: ', a, 'b: ', b);
}
swapNumb(2, 3);
Solution – 2 – Using Bitwise XOR
function swapNumb(a, b){
console.log('Before swap Output: ','a: ', a, 'b: ', b);
a = a ^ b;
b = a ^ b;
a = a ^ b;
console.log('After swap Output: ','a: ', a, 'b: ', b);
}
swapNumb(2, 3);