es6-array, object, string deconstruction

Source: Internet
Author: User

In ES6
var can be used as a global declaration
Let can be a partial declaration
Const definition constant, no further modification, or error

Array Deconstruction:
let [a,b,c]=[1,2,3];

Pay attention to the same structure and position

Allows a default value of

There are different times when the value is undefined and null
Undefined, the memory is not value, so will go to the default value
NULL, the memory is value, and is displayed as null

Object structure:
Let {a,b}={a: ' Ten ', B: ' 20 '} Note that the object key is not in the corresponding position, it is the corresponding key

Easy Error Point:
When a key to an object has been declared before, it needs to be wrapped or it will be an error.

let c;{c}={c:‘123‘};console.log(c)VM185:2 Uncaught SyntaxError: Unexpected token =let c;({c}={c:‘123‘});console.log(c)VM186:3 123

String structure, (in fact, the string is treated as an array)

const [a,b,c,d,e]="asdfg"

es6-array, object, string deconstruction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: [email protected] and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.