Modern JS (ES6+)

Optional chaining & nullish coalescing

Safely reading deep properties and defaulting only for null/undefined.

beginner All levels

Optional chaining (?.) short-circuits to undefined instead of throwing when a value in a chain is null or undefined — no more long a && a.b && a.b.c guards.

`?.` is asking "if this door exists, open it" instead of crashing into a wall; `??` is a spare key used only when there is genuinely no key.

Key concepts

1
Nullish coalescing (??) returns the right-hand side only when the left is null or undefined — unlike ||, it does not treat 0, "" or false as missing.
Nullish coalescing??nullundefined||
2
Together they make reading optional, deeply nested data concise and bug-resistant.