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:
HBuilder
JavaScript
ES6
Browser
Screenshot tool
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:
Second, save the code and run it directly with Node.js, and view the print in the console, as shown below:
In the third step, the variables x, y, and z are declared and assigned together using an array-like declaration, as shown below:
Step 4, save the code again and run it, you can see the printed value of the variable, as shown below:
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:
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:
Note the deconstructive assignment method for ES6 variables
Pay attention to fair use... Perform deconstruction assignment