DEV Community

Discussion on: Terrible interview question: Swap variables without a temporary

Collapse
 
learnersbucket profile image
Prashant Yadav

The best approach in javascript is to use an array destructuring

let a = 10;
let b = 20;
[a, b] = [b, a];
console.log(a, b);
20, 10