DEV Community

Discussion on: Swapping two numbers, w/o a temp variable

Collapse
 
clavinjune profile image
Clavin June • Edited

Why don't u use XOR operator?
a = a XOR b
b = a XOR b
a = a XOR b

Collapse
 
hakash profile image
Morten Olsrud

Cool trick!

Collapse
 
mateiadrielrafael profile image
Matei Adriel

In js u can use ^ as xor