9.7 swap(a,b)的第二种方法
作者:互联网
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没有改变
标签:function,console,log,swap,第二种,swapa,var,9.7 来源: https://blog.csdn.net/qq_44805237/article/details/108466127