Python Objects, Key-Value Pairs & Destructuring
JavaScript objects store keyed collections of properties and methods. Destructuring assignment allows unpacking values from objects and arrays directly into distinct variables.
"An object is like an ID card: it has labeled fields (Name, Age, Department). Destructuring is reading off just the name and age onto a visitor pass in one quick step."
Deep Dive: How It Works
Object Literal: const user = { name: "Alex", role: "Dev" };
Property Access: Dot notation (user.name) vs Bracket notation (user["role"]).
Object Destructuring: const { name, role } = user; extracts properties by name with optional default fallbacks.
Syntax Blueprint
const { title, price = 0 } = product; ──▶ Unpacks product.title and product.priceDestructuring provides clean, readable parameter extraction and property assignments.
Core Rules to Remember



Common Beginner Traps & How to Fix Them
Destructuring undefined or null.Why it happens: const { name } = undefined throws a TypeError: Cannot destructure property of undefined.
How to fix: Provide a default empty object fallback: const { name } = user ?? {};.
Live Interactive Example
Hit Run Code to see it liveYour Turn: Micro Challenge
No pressure! Edit the starter code below and test your solution with instant feedback.
Destructure user profile object
Given const player = { name: "Valkyrie", level: 42, role: "Warrior" };
Destructure const { name, level } = player;
Print "Player: Valkyrie (Level 42)".
Finished reading and practicing?
Mark this lesson as completed to update your course progress.