Assigning to new variable names and providing default values.
There are two popular ways to accomplish this: using a temporary variable and XORing (with some restrictions).
In this example, we use destructuring assignment to swap values of a and b variables. . 18.
Using destructuring assignment (ES6+) Edit.
Here, parseInt() is used because prompt() takes input from the user as a string.
Assigned a default value in case the unpacked value is. 4.
. This method only uses the two variables and swaps the value of the variables using arithmetic operators + and -.
Assigned a default value in case the unpacked value is.
For example, XOR of 10. How to Swap Two Array.
Enter the first variable: 4 Enter the second variable: 2 The value of a after swapping: 2 The value of b after swapping: 4 Here, a new es6 feature, called destructuring assignment [a, b] = [b, a] , is used to swap the value of two variables.
getElementById ('output'); output.