Optional Chaining & Safe Access
Optional chaining (?.) prevents errors when accessing properties that might not exist. It's essential for handling incomplete or variable data structures.
The Problem
Basic Optional Chaining
Optional Chaining with Arrays
Optional Method Calls
Nullish Coalescing (??)
Combine ?. with ?? for default values:
Exercise: Safe Navigation
Exercise: Array Safety
Key Points
?.stops and returnsundefinedif value is null/undefined- Works with properties:
obj?.prop - Works with arrays:
arr?.[0] - Works with methods:
fn?.() - Combine with
??for default values ??only replaces null/undefined, not falsy values
Up next · Lesson 11 of 23
Transforming with map()
1 min read
10 of 23 lessons done

Ask Byte about this lesson
A private chat about this lesson. Byte has read the whole lesson, answers in seconds, and shows the section each answer comes from. Ask follow-ups in any language.
Questions & Answers
Public questions about this lesson. The AI Tutor answers right away in your language, the FreeAcademy team checks answers, and every learner can read them.

