JavaScript program to swap two variables using es6(ES2015) destructuring assignment

Here, a new es6 feature, called destructuring assignment [a, b] = [b, a], is used to swap the value of two variables. If [a, b] = [1, 2, 3], the value of a will be 1 and value of b will be 2.

First a temporary array [b, a] is created. Here the value of [b, a] will be [2, 4].
The destructuring of the array is done, i.e [a, b] = [2, 4].
As a result, the value of the variables are swapped.

[mai mult...]