← Back to Gists

Array destructuring swap

📝 JavaScript
mvargas
mvargas · Level 1 ·

Swaps two values 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.