- Published on
- David Rhodes
Looking to learn about or brush up on the optional chaining operator? Here are three things I learned while checking in with MDN and trying out a few test cases on their detail page for Optional Chaining, which shows:
The optional chaining operator ?. permits reading the value of a property located deep within a chain of connected objects without having to expressly validate that each reference in the chain is valid.
Second, it's not just for strict objects, as an Object can also be a function or an array, nested within another object
. Here we apply optional chaining to a nested method and nested array within the adventurer object.:
Third, it returns undefined when tested values are nullish, which is null or undefined, as you can see in all three test cases below where we try it with a property that doesn't exist.
Next up? The Nullish Coalescing Operator.