交换变量值
语法:
var 空格 变量名a;变量名b= 值1;变量名b= 值2;
变量名a=变量名b;
变量名b=变量名c;
变量名c=变量名a;
代码示例:
<script>
var a;
var b = 1;
var c = 2;
a = b;
b = c;
c = a;
console.log(b, c);
</script>
运行结果:
交换变量值
语法:
var 空格 变量名a;变量名b= 值1;变量名b= 值2;
变量名a=变量名b;
变量名b=变量名c;
变量名c=变量名a;
代码示例:
<script>
var a;
var b = 1;
var c = 2;
a = b;
b = c;
c = a;
console.log(b, c);
</script>
运行结果: