Home >Web Front-end >JS Tutorial >What is Destructuring Assignment in JavaScript?

What is Destructuring Assignment in JavaScript?

Linda Hamilton
Linda HamiltonOriginal
2024-11-16 01:50:02440browse

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:

  • Opera 10.30 and above
  • Firefox 3.6.x and above

However, it is not supported in older browsers such as:

  • Opera 10.60
  • Chrome (prior to version 5)

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn