Get the App
SLTechnology News&Howtos  ›  Development  › 

How js uses ^ to complete the value exchange

Shulou Source: shulou.com Published: 2022-06-01 05:13:12 10月03日 Update

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!

Tags: Articles integers values traditions interests variables at the same time arrays ways more faster friends knowledge editing industry information information channels channels references learning Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Information Apple Linux Huawei