What Is Destructuring in JavaScript?
Destructuring lets you unpack values from arrays or properties from objects into distinct variables using a concise syntax that mirrors the shape of the data...
Published November 21, 2026
Destructuring unpacks values from arrays or properties from objects into separate variables in one statement: const { name, age } = user and const [a, b] = list.
The concept
Object destructuring matches by property name; array destructuring matches by position. You can rename, set defaults and nest patterns.
It shines in function parameters, imports and handling API responses.
Unpack into names
const { name, city = 'N/A' } = { name: 'Ada' }
name = 'Ada', city = 'N/A'
const [x, , z] = [1, 2, 3]
x = 1, z = 3
Practical examples
Rename and default
const { name: fullName, age = 18 } = userNested
const { address: { city } } = userFunction parameters
function show({ id, name }) { return `${id}: ${name}` }Swap variables
let a = 1, b = 2;
;[a, b] = [b, a]Common mistakes
- Destructuring null or undefined (TypeError).
- Forgetting parentheses around object destructuring assignment.
- Deep nesting that hurts readability.
Key takeaways
- Unpack by name or position.
- Defaults and renames available.
- Great for params and API data.
FAQ
How do I avoid errors on undefined?
Provide defaults: const { a } = obj ?? {}.
Can I destructure Map or Set?
Yes, they are iterable (array-style).