function swap(a, b){
a = a + b ;
b = a - b ;
a = a - b ;
}
function (a, b){
[a, b ] = [b , a ]
}
function swap(a, b){
a = a + b ;
b = a - b ;
a = a - b ;
console.log(a, b );
}
function swapa(a, b){
[a, b ] = [b , a ];
console.log(a, b );
}
var a = 1;
var b = 2;
swap(a, b);
swapa(a, b);
console.log(a, b );
需要注意的是,函数作用域里面的a,b改变了,但是全局的a,b没有改变