Swap two variables without the third variable

不依赖第三个变量,交换两个变量

swap-new.js

let x = 1;
let y = 2;
[x, y] = [y, x]; // x = 2, y = 1;
console.log('x:',x);
console.log('y:',y);

版权声明:著作权归作者所有。

thumb_up 1 | star_outline 0 | textsms 0