JavaScript 2025 · Objects and data

Swap two variables

Use array destructuring to swap without a temporary variable.

[a, b] = [b, a];

Official JavaScript 2025 documentation

More objects and data commands

All objects and data commands · JavaScript 2025 cheatsheet

Was this page helpful?