How js uses ^ to complete the value exchange
This article mainly introduces how js uses ^ to complete the value exchange, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand.
Use ^ to complete the value exchange
Before the deconstruction of ES6 is assigned, it is faster in this way (but it must be an integer):
/ /-before-let temp = a; a = b; b = temp / / traditional, but with the help of temporary variable b = [a, a = b] [0] / / with the help of the array / /-after-can only be used for integers let a = 7 let b = 1 a ^ = b ^ = a ^ = b console.log (a) / / 1 console.log (b) / / 7 [a, b] = [b, a] / / ES6, deconstructing assignment Thank you for reading this article carefully. I hope the article "how js uses ^ to complete the value exchange" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!