WBF Academy
Functional Beginner 2 min read

Optional Chaining & Nullish Coalescing

Safely access nested properties without crashes

JS Academy

JS Academy

JavaScript Engineer

1 month ago

Optional chaining (`?.`) lets you safely read the value of a property deep within a chain of object references without checking whether each reference is nullish. If any reference in the chain is `null` or `undefined`, the expression short-circuits and returns `undefined` instead of throwing. The nullish coalescing operator (`??`) provides a fallback value only when the left-hand side is `null` or `undefined`, making it more precise than `||` which triggers on any falsy value like `0` or empty strings.

#javascript #optional-chaining #nullish-coalescing #es2020