JavaScript Destructuring Explained Simply

In JavaScript, destructuring means extracting values from arrays or objects and storing them directly into variables. It reduces repetitive code and makes data handling cleaner. Instead of writing multiple lines to access values one by one, destructuring allows you to pull them out in a single statement.
With array destructuring, values are assigned based on position. For example, before destructuring you would write:
const colors = ["red", "blue"];
const first = colors[0];
const second = colors[1];
Using destructuring, the same code becomes shorter:
const colors = ["red", "blue"];
const [first, second] = colors;
This directly maps array positions to variables, like assigning seats in order
With object destructuring, values are extracted using property names. Before destructuring:
const user = { name: "Rahul", age: 22 };
const name = user.name;
const age = user.age;
After destructuring:
const user = { name: "Rahul", age: 22 };
const { name, age } = user;
This is useful when working with API responses or function data because object properties can be picked directly
You can also set default values if a property is missing.
const { city = "Kolkata" } = { name: "Rahul" };
console.log(city); // Kolkata
This prevents undefined values and keeps code safer
The main benefit of destructuring is cleaner code, fewer repeated references, and easier reading. A simple way to see it is: destructuring takes data out of a container and places it directly into variables