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
JavaScript 2025 · Objects and data
Use array destructuring to swap without a temporary variable.
[a, b] = [b, a];
Official JavaScript 2025 documentation
Was this page helpful?