← Back to Gists

Array destructuring swap

📝 JavaScript
sarahhall
sarahhall · Level 1 ·

Swaps two variables without a temporary variable using array destructuring.

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

Comments

No comments yet. Start the discussion.