skill

341Currently online
145Today's Reading
43Share Today
Multilingual display

How do I declare multiple variables in ES6 and display them separately

2018-04-25 01:36:30

In the new JavaScript standard ES6, variable deconstruction assignment is another feature, which can easily declare multiple variables. You can also bind array variables. Here are a few examples to illustrate the use of deconstructed assignment, as follows:

Tools/Materials
1

HBuilder

2

JavaScript

3

ES6

4

Browser

5

Screenshot tool

Methods/Steps
1

First, double-click on the HBuilder editor, use the let keyword to declare three variables x, y, and z, and print them separately, as shown below:

2

Second, save the code and run it directly with Node.js, and view the print in the console, as shown below:

3

In the third step, the variables x, y, and z are declared and assigned together using an array-like declaration, as shown below:

4

Step 4, save the code again and run it, you can see the printed value of the variable, as shown below:

5

In the fifth step, you can also use three dots to declare a variable, but this variable cannot be preceded by three dots, as shown below:

6

Step six, use... Declare variables, the first assigned to the specified variable, the remaining elements are given to the last variable, as shown in the following figure:

Matters needing attention
1

Note the deconstructive assignment method for ES6 variables

2

Pay attention to fair use... Perform deconstruction assignment

Recommendation