Get the App
SLTechnology News&Howtos  ›  Development  › 

How to implement variable Exchange in es6

Shulou Source: shulou.com Published: 2022-05-31 20:50:49 10月03日 Update

This article focuses on "how to achieve variable exchange in es6", interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to exchange variables with es6.

Variable exchange method: 1, with the help of the third variable c, the syntax "c", so that the values of variables an and b can be interchangeable; 2, the use of array subscript re-assignment, the syntax "a = [a]; b];"; 3, the use of array deconstruction assignment, syntax "[a] = [b, a];"

The operating environment of this tutorial: windows7 system, ECMAScript version 6, Dell G3 computer.

The method of realizing variable Exchange in es6

Method 1: with the help of third variable

There are two variables an and b, and the third variable c can be used to exchange variables.

Assign a value to c first

Before assigning a b value to a

Finally, assign the c value to b

Var axiom 1 / 1 / 2 / 2 / 1 / 1 / 2

Method 2: re-assign using array subscript

Var a = 3, b = 4TX a = [aMaginb]; b = a [0]; a = a [1]; console.log (ameme b)

Method 3: use the deconstruction assignment of the array to exchange the value of the variable

Var a = 3, b = 4; [console.log b] = [b, a];

At this point, I believe you have a deeper understanding of "es6 how to achieve variable exchange", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Variables methods arrays syntax subscript content learning practical deeper two interest practicality practical easy to operate tutorials more friends environment computer system Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Shulou Tech Info Microsoft vpn NVidia