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

What is Destructuring Assignment in JavaScript?

Linda Hamilton
Release: 2024-11-16 01:50:02
Original
443 people have browsed it

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;
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template