Destructuring
In one line
Destructuring is a syntax that unpacks values from arrays or properties from objects into distinct variables.
In simple words
Destructuring is a shorthand for extracting values from arrays and objects. Instead of accessing properties one at a time, you can unpack multiple values in a single statement.
Array destructuring uses square brackets: const [a, b] = [1, 2] assigns 1 to a and 2 to b. Object destructuring uses curly braces: const { name, age } = user extracts the name and age properties.
You can rename variables (const { name: firstName } = user), set defaults (const { port = 3000 } = config), and skip elements in arrays (const [, second] = arr). Destructuring is commonly used in function parameters and import statements.
Example
const user = { name: "Ada", age: 36 };
const { name, age } = user;
console.log(name, age); // "Ada" 36
const [first, , third] = [10, 20, 30];
console.log(first, third); // 10 30Object destructuring extracts properties by name; array destructuring by position.
Related terms
Related Resources
Related Lessons
- Objects
Learn about destructuring.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.