Posts

Destructuring in JavaScript

Destructuring is a powerful feature in JavaScript that allows developers to extract data from arrays or objects and assign them to variables in a single step. This feature was introduced in ECMAScript 6 (ES6) and has since become a popular technique among JavaScript developers. Destructuring syntax allows for easy extraction of values from arrays and objects using a shorthand notation. The syntax uses curly braces ({}) for objects and square brackets ([]) for arrays. Here's an example: // Destructuring an array const [a, b, c] = [ 1 , 2 , 3 ]; console. log (a); // 1 console. log (b); // 2 console. log (c); // 3 // Destructuring an object const { name, age } = { name: 'John' , age: 30 }; console. log (name); // 'John' console. log (age); // 30
Recent posts