Home >Web Front-end >JS Tutorial >What is Destructuring Assignment in JavaScript?
Destructuring Assignment Syntax in JavaScript
In JavaScript, square brackets on the left-hand side of a variable assignment indicate destructuring assignment, a syntax introduced in JavaScript 1.7 and ECMAScript 6.
Example of Destructuring Assignment
Consider the following code:
var myList = [1, 2, 3]; var a, b, c; [a, b, c] = myList;
In this example, the square brackets are used in the assignment to destructure the myList array. The elements of the array are assigned to the variables a, b, and c.
Browser Support for Destructuring Assignment
Destructuring assignment is supported in modern browsers such as:
However, it is not supported in older browsers such as:
ECMAScript Compatibility
Destructuring assignment is not part of ECMAScript 5. It was introduced in JavaScript 1.7 and formalized in ECMAScript 6.
The above is the detailed content of What is Destructuring Assignment in JavaScript?. For more information, please follow other related articles on the PHP Chinese website!