The following code will output 0,2 to the console:
let a =2, b= 0;
( () => {
[a,b]=[b,a];
}) ();
console.log(a,b)
I think I kinda understand what's happening here:
() => {
[a,b]=[b,a];
}
an arrow function and destructuring to exchange the places of the variables. But why it has to be enclosed in parentheses and also have additional () in the end to work is beyond my understanding. I tried reading MDN on arrow function expressions to no avail. What exactly is happening here?