JS implementation uses no intermediate variable temp to implement two variable value exchange methods, jstemp
1. Use addition and subtraction;
Var a = 1; var B = 2; a = a + B; B = a-B; a = a-B;
2. Use multiplication and division (multiplication and division are more like the ing from addition and subtraction to multiplication and division operations)
Var a = 1; var B = 2; a = a * B; B = a/B; a = a/B;
Note: This method can be used to exchange integer and floating-point values, but loss of precision may occur when processing floating-point values, and B cannot be 0 when multiplication and division are performed;
3. array flexibility
Var a = 1; var B = 2; a = [B, B = a] [0];
Summary
The above is a small series of JS implementations that don't use the intermediate variable temp to implement two variables worth exchanging methods. I hope to help you. If you have any questions, please leave a message for me, the editor will reply to you in time!