rasti.hil@hilandco.com +41 79 367-9677

Search This Blog

Swap two variables

Here is a small reminder to myself since, from time to time I spent some time thinking on it...


var a = 5,
    b = 3;
a = a + b;  // a = 5 + 3 = 8
b = a - b;  // b = 8 - 3 = 5
a = a - b;  // a = 8 - 5 = 3

console.log(a, b);
// 3 5