var a = 1 , b = 2; // a==1, b==2
, the simplest way I can think of to switch the values
b is this:
a = [b, b=a]; // a==2, b==1
Right? Of course it is slower than using just a temporary variable (see http://jsperf.com/variable-switch), which is also something one should know about.
In ES6 this can be done simply by something called destructuring assignment, which for arrays looks like this:
[a, b] = [b, a]; // a==2, b==1