Unpack Properties
Destructuring lets you pull properties into variables by name.
It reduces repeated object.property access.
JavaScript Tutorial
Object destructuring lets you extract properties into variables in a concise way.
It makes code more readable by reducing repeated access.
Destructuring is common in function parameters and API responses.
It helps you write cleaner and more expressive code.
const { prop } = obj
const { prop: alias = defaultValue } = objconst user = { name: "Ava", role: "admin" };
const { name, role } = user;
console.log(name, role);Pull properties into variables.
const user = { name: "Ava" };
const { name: fullName } = user;
console.log(fullName);Rename properties during destructuring.
Destructuring lets you pull properties into variables by name.
It reduces repeated object.property access.
You can rename variables and provide default values.
This is useful when data may be missing.
Destructure nested objects carefully to avoid undefined errors.
Combine with defaults when needed.
Without
const name = user.name;
const role = user.role;With
const { name, role } = user;Provide defaults or check objects before destructuring.
Keep destructuring readable and shallow when possible.
Use name: alias syntax for clarity.
Use const { prop: alias } = obj.
Use = defaultValue in the pattern.
It reduces repeated property access and improves readability.
Practice: Destructure a user object to extract name and city.
const user = { name: "Ava", address: { city: "Delhi" } };
// TODO: destructure name and city
One Possible Solution
const user = { name: "Ava", address: { city: "Delhi" } };
const { name, address: { city } } = user;
console.log(name, city);It assigns properties to variables by name.
Yes, use const { prop: alias } = obj.
Use const { prop = defaultValue } = obj.
Try renaming and adding defaults.