一、添加临时变量(最常见)
var a = 1, b = 2, c; c = a; a = b; b = c;
二、算数运算(仅限number类型)
var a = 3, b = 5; a = a - b; // a = -2 , b = 5; b = a + b; // a = -2, b = 3; a = b - a; // a = 5, b = 3;
三、数组特性
var a = 1; b = 2; a = [ a , b ]; b = a[ 0 ]; a = a[ 1 ];
四、ES6解构
let a = 3, b = 7; [ a , b ] = [ b , a ];
原文地址:https://www.cnblogs.com/lmyxywy/p/10988974.html
时间: 2024-10-06 11:06:09