DEV Community

Cover image for Goodbye tmp 👋
sk9
sk9

Posted on

Goodbye tmp 👋

We used tmp a lot in JavaScript.
For example, like this ...

let a = [0, 1];
const tmp = a[1];
a[0] = a[1];
a[1] = tmp;
console.log(a); // 1, 0

If you don't like this style, what about the following?

let a = [0, 1];
[a[1], a[0]] = [a[0], a[1]];
console.log(a); // 1, 0

😉

Top comments (0)