第一种

  1. var a = 1,
  2. b = 2;
  3. a = a + b; // a = 3, b = 2
  4. b = a - b; // a = 3, b = 1
  5. a = a - b; // a = 2, b = 1
  6. console.log(a,b);

image.png

第二种

//ES6解构赋值

        let a = 1,
            b = 2;
        [a, b] = [b, a];
        console.log(a, b);


image.png