花式交换两个数值
方案一
var a = 1, b =2;
a = [b, b = a][0];
console.log(a, b); //2 1
方案二
var a = 1, b =2;
a = a ^ b;
b = a ^ b;
a = a ^ b;
console.log(a,b) //2 1
方案三
let a=1,b=2;
[a,b]=[b,a]
var a = 1, b =2;
a = [b, b = a][0];
console.log(a, b); //2 1
var a = 1, b =2;
a = a ^ b;
b = a ^ b;
a = a ^ b;
console.log(a,b) //2 1
let a=1,b=2;
[a,b]=[b,a]