← Back to Gists

Array destructuring swap

📝 JavaScript
michaelsimmons
michaelsimmons · Level 4 ·

Swaps two variables without a temporary variable by using array destructuring assignment.

JavaScript
let a = 5;
let b = 10;
[a, b] = [b, a];
console.log(a, b);

Comments

No comments yet. Start the discussion.