What is Destructuring in JavaScript

 The destructuring  is a JavaScript expression that makes it possible to unpack values from arrays, or properties from objects, into distinct variables.

Demo URL



Syntax : let a, b, rest;

[a, b] = [10, 20];


console.log(a);

// expected output: 10


console.log(b);

// expected output: 20


[a, b, ...rest] = [10, 20, 30, 40, 50];


console.log(rest);

// expected output: Array [30,40,50]


No comments:

Post a Comment

Angular's new httpResource and a bonus hidden feature

  The first   release candidate   for   Angular 19.2   is out, and it includes the new experimental   httpResource . This is essentially a s...

Best for you