Destructuring Assignments

Destructuring Assignments: The destructuring assignment syntax in JavaScript makes it possible to unpack values from arrays or properties from objects into distinct variables.


Example:

```

// Array destructuring

const arr = [1, 2, 3];

const [a, b, c] = arr;

console.log(a, b, c); // 1 2 3


// Object destructuring

const obj = {x: "X", y: "Y"};

const {x, y} = obj;

console.log(x, y); // X Y

```

In both examples, the variables a, b, c, x, and y are assigned new values from the array or object on the right side of the assignment.

Comments

Popular posts from this blog

Abstract Classes and Interfaces

Optional Chaining

Logical Or operator || vs Nullish Coalescing