swap two numbers without temp in javascript 1

swap two numbers without temp in javascript

let a = 5, b = 6;
[a, b] = [b, a];

// Destructuring Assignment Array Matching

Here is what the above code is Doing:
1. The first line creates an array with two elements, 5 and 6.
2. The second line assigns the first element of the array to a and the second element to b.
3. The third line swaps the values of a and b by destructuring the array.

Similar Posts