Keyed Data Structures in JavaScript II
JavaScript·3 min read·Jan 1, 2025
Destructuring objects
The destructuring assignment syntax allows you to selectively extract properties from objects and assign them to distinct variables in a concise and structured way.
let { key, ..., keyN } = object;Note: When destructuring a property that doesn't exist within the object, the specified variable will hold the
undefinedvalue.
Example
Let's consider this script:
const bike = { brand: 'Honda', model: 'Africa Twin'};const { brand, model } = bike;console.log(brand);console.log(model);Unlock the Build CLI Apps in JavaScript & Node.js module
Learn how to build, integrate, and safeguard scalable CLI tools, scripts, and apps with JavaScript, Node.js, npm, and Git.
You get immediate access to:
- 45 focused lessons across JavaScript, Node.js, npm, and Git
- 17 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle