← Back to Gists

Array destructuring swap

📝 JavaScript
catherinemorgan
catherinemorgan · Level 3 ·

Swap two variable values 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.