MDGSF Software Engineer

[JavaScript] 交换两个变量的值

2019-10-10
mdgsf
Web

a = 1;
b = 2;

// method 1
[a, b] = [b, a]

// method 2
// b = [a, (a = b)][0];

// method 3
// or use destructuring
// [b] = [a, (a = b)];

console.log(a, b);

weixingongzhonghao

Comments

Content