Swap Array Elements Inline
Category: JavaScript
Explanation
Array destructuring also works for index references to arrays. In this case, you basically tell the runtime the following:
Take the value at array[2] and place it inside array[0], and then take the value at array[0] and place it at array[2], while implicitly creating a temporary variable because you don’t want to lose the original values.
The runtime creates the temporary variable automatically for you, under the hood, so you don’t have to deal with it in your code.
Without array destructuring, your code would look like this: