Destructuring in JavaScript
Have you ever written code like this? ```js id="before1" const user = { name: "Rahul", age: 22 }; const name = user.name; const age = user.age; It works—but it’s **repetitive**. Destructuring lets ...

Source: DEV Community
Have you ever written code like this? ```js id="before1" const user = { name: "Rahul", age: 22 }; const name = user.name; const age = user.age; It works—but it’s **repetitive**. Destructuring lets you **extract values from arrays or objects in a cleaner way**. --- ## 🧠 What Is Destructuring? Destructuring is a JavaScript feature that allows you to: > Unpack values from arrays or objects into **distinct variables** in a single step. --- ## 🔹 Destructuring Arrays Instead of: ```js id="arrayBefore" const numbers = [10, 20, 30]; const first = numbers[0]; const second = numbers[1]; Use destructuring: ```js id="arrayAfter" const [first, second] = [10, 20, 30]; console.log(first); // 10 console.log(second); // 20 ### ✅ Notes: * Order matters in arrays * You can skip items with commas: ```js id="arraySkip" const [ , , third] = [10, 20, 30]; console.log(third); // 30 📊 Array Destructuring Visual [10, 20, 30] → first = 10, second = 20, third = 30 🔹 Destructuring Objects Instead of: ```js