JavaScript7 min read
JavaScript Optional Chaining (?.)
Master optional chaining. Safely access nested object properties without errors.
Alex Thompson
December 19, 2025
0.0k0
JavaScript Optional Chaining
The Problem
Accessing nested properties can cause errors:
const user = { address: null };
user.address.city; // Error! Cannot read property
The Solution: Optional Chaining
const user = { address: null };
user.address?.city; // undefined (no error!)
Usage
user?.name;
user?.address?.city;
user?.greet?.();
Key Takeaway
Optional chaining (?.) safely accesses nested properties. Returns undefined instead of error. Essential for working with API data.
#JavaScript#Optional Chaining#ES2020#Objects#Intermediate