You can use array destructuring for easy swapping the values of 2 variables together. Here is how 👇
Sie können die Array-Destrukturierung verwenden, um die Werte von 2 Variablen einfach zu vertauschen. Hier ist, wie 👇
let x = 1;
let y = 5;
[x, y] = [y, x];
console.log(x); //5
console.log(y); //1
Top comments (2)
Can you point me to anything to help me understand how this works. I understand what you are doing, but just don't understand the mechanics of it, what is happening in terms of memory etc.
thank u so much