Object Destructuring
Object destructuring matches by property name. Rename variables with key: alias, set defaults with = value.
Object destructuring matches by property name. Rename variables with key: alias, set defaults with = value.
const { name, age } = user;
const { name: userName, role = "user" } = user; // rename + default
// Nested
const { address: { city, zip } } = user;
// All remaining
const { id, ...rest } = user; // rest = all except id
// In function params
function render({ title, className = "default" }) { }
Combine rename and default: const { theme: { color: c = "blue" } = {} } = config.
More in JavaScript