How to swap variables in JavaScript

Syntax
By Jad Joubran · 
Last updated Feb 27, 2024
let firstName = "Doe";
let lastName = "Sam";

// Swap
[firstName, lastName] = [lastName, firstName];

console.log(firstName, lastName);
Sam Doe