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

CPU vs GPU Architecture

  CPU vs GPU Architecture CPU (Central Processing Unit) and GPU (Graphics Processing Unit) have distinct architectural differences, optimize...

Best for you