Swapping

Traditional way

We need to declare an extra variable to hold one of the values while we swap them up:

var a = 1;
var b = 2;

var temp = a;
a = b;
b = temp;

console.log(a);
console.log(b);

Fancier way

There is an option to use array destructuring to implement the swapping:

var a = 1;
var b = 2;

[a, b] = [b, a];

console.log(a);
console.log(b);

And with this apporoach, we could do multiple at the same time.

Pretty neat! :bowtie: