Object Essentials — Creation · Access · Destructuring · Spread
Object Essentials — Creation · Access · Destructuring · Spread
🎯 After reading this lesson
After finishing this lesson, you will be able to confidently do the following 3 things.
- ▸✅ Destructuring + default values + rename + rest patterns
- ▸✅ Immutable updates with spread + shallow copy limitations
- ▸✅ Optional chaining ?. + ?? default value combination
Keep the learning objectives as a checklist and close the lesson once you can answer all of them.
Creating and Accessing Objects — Dot vs Bracket Notation
Object Literals
The most commonly used form. Almost identical to JSON, but keys can omit quotes (JS literals only).
Dot Notation vs Bracket Notation
Rule: Use dot notation when the key is a fixed string. Use bracket notation for dynamic keys.
When the Key Violates Identifier Rules
When an API response has kebab-case keys, bracket notation is required.
Modify · Add · Delete
Shorthand Properties
When the variable name matches the key, you can omit the repetition. This is the basis for the <Comp {...props} /> pattern in React.
Destructuring Assignment — *The Essential Vocabulary for Vibe Coding*
Basic Destructuring
Extract only the keys you need from an object into variables. This appears in every function signature in AI-generated code.
Renaming
Default Values — When a Key Is Missing or undefined
Nested Destructuring
In Function Parameters — The React Component Standard
99% of React code worldwide uses this pattern. If you can't read it, every component looks like a foreign language.
Array Destructuring
React's useState is the most frequently seen example of this syntax:
Spread · Object Static Methods · Optional Chaining
Spread ... — Unpacking Objects
The cornerstone of immutable updates. The standard pattern for updating React state:
Later keys overwrite earlier ones:
Shallow Copy Limitations
Only the first level is copied. Nested objects share references. For a deep copy:
3 Object Static Methods
entries is used when you need both key and value simultaneously in a loop:
Optional Chaining ?. — Essential for Parsing API Responses
Without ?.:
5 words collapsed into 1. It always appears in AI-generated code.
Nullish Coalescing ?? — Default Values
Combining optional chaining results with a default value is a go-to pattern.
🤖 Try asking AI like this
- ▸"Refactor this function parameter using destructuring"
- ▸"Make this object update immutable using spread"
- ▸"Make this deep object access safe using optional chaining"