Skip to content

How to Swap Variables' values Using Array Destructuring

twitter logo github logo ・1 min read  

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
twitter logo DISCUSS
Classic DEV Post from Jul 20 '19

What Makes You a Great Programmer on The Team?

Majority of software developers are aspired to be not only a competent professional but also a great one.

Islam Sayed profile image
A Freelance Front-End Web Developer, tech writer, and mentor at Udacity.