← #20 Track the focused element with Chrome DevTools
#21

Swap two variables

Topics: JavaScript

There are a few ways to swap two variables without using a temporary variable:

[a, b] = [b, a];

// Or
a = [b, b = a][0];

// Or
a = (x => x)(b, b = a);

If both variables are numbers, then you can swap them with operators:

a = b + (b = a, 0);

// Or
a = b * (b = a, 1);
Fix a typo or suggest an improvement
#22 Use an underscore to name unused argument