The value of one variable is assigned to an other and vice versa.
//Defining the variables with values var a=1,b=2; // swap logic a = [b][b = a, 0]; // [b] - Puts b in an array //[b = a,0] - Assign a to b and return 0 // alerting the swapped variables with values alert("Swapped: a="+a+",b="+b+".");
You can also try this traditional method(oldfolks) but the above one is well reformed.
var a = 1; var b = 2; a = a + b; b = a - b; a = a - b; alert("Value of a" + a + " and value of b"+b);