Ruphaa's Notes

How to swap variables using array destructuring in JS

js

let x = 2;
let y = 3;
[x, y] = [y, x];

console.log(x); // 3
console.log(y); // 2