Комментарии:
You could at least put it into a function and you forgot to document your code 💢
Ответитьlet a = 10;
let b = 20;
[a, b] = [b, a];
console.log(a);
console.log(b);
In case anyone is interested in to swap variables without declaring any temp variable, you can write:
a = a + b;
b = a - b;
a = a - b;
At the end, variables have swapped