Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to implement variable Exchange in es6

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report