Today I learned a straight-forward way to swap the values of two variables in JavaScript.
Say var a = 10 and var b = 20.
Previously, I would use the following (tedious) strategy to swap the values:
var temp = a; // temp is now 10
a = b; // a is now 20
b = temp; // b is now 10A quicker way to do this is:
b = [a, a = b][0];Finally, in ECMAScript 6 you can use destructuring assignment:
[a, b] = [b, a];