Home > Article > Web Front-end > What is Destructuring Assignment and how does it work in JavaScript?
Destructuring Assignment: Understanding Square Brackets in Variable Declarations
In the code snippet provided, the square brackets on the left-hand side of the variable assignment ([a, b, c] = myList) have to do with a feature called destructuring assignment.
What is Destructuring Assignment?
Introduced in JavaScript 1.7 and ECMAScript 6, destructuring assignment allows you to unpack values from arrays or properties from objects into individual variables.
Syntax:
Array Destructuring: [variable1, variable2, ...] = array
Object Destructuring: ({ property1: variable1, property2: variable2, ... } = object)
Example from the Code Snippet:
In the given code, the square brackets ([a, b, c]) on the left-hand side of the assignment operator (=) are used for array destructuring. It unpacks the values from the myList array into the individual variables a, b, and c.
Browser Support:
Destructuring assignment is supported in newer browsers, including:
ECMAScript Standard Compliance:
Destructuring assignment is not part of ECMAScript 5. It was introduced later in JavaScript 1.7 and formalized in ECMAScript 6. Therefore, it is not considered compliant with ECMAScript 5.
The above is the detailed content of What is Destructuring Assignment and how does it work in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!