使用第三方变量
var a = 1;
var b = 2;
var temp;
temp = a; //1
a = b; //2
b = temp;//1
console.log("a",a,"b",b);//a 2 b 1
使用求和
var a = 1;
var b = 2;
a = a+b;//3
b = a-b;//2
a = a-b;//1
console.log("a",a,"b",b);//a 2 b 1
使用第三方变量
var a = 1;
var b = 2;
var temp;
temp = a; //1
a = b; //2
b = temp;//1
console.log("a",a,"b",b);//a 2 b 1
使用求和
var a = 1;
var b = 2;
a = a+b;//3
b = a-b;//2
a = a-b;//1
console.log("a",a,"b",b);//a 2 b 1