DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,673 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to Swap Variables' values Using Array Destructuring
Islam Sayed
Islam Sayed

Posted on

How to Swap Variables' values Using Array Destructuring

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 (0)

🌚 Browsing with dark mode makes you a better developer.

It's a scientific fact.