Declare a function name swap Values for swapping the values in javascript code example
Example 1: swap two variables javascript
var a = 1,
b = 2;
b = [a, a = b][0];
Example 2: swap function javascript
function swap(x, y) {
var t = x;
x = y;
y = t;
return [x, y];
}
console.log(swap(2, 3));