JavaScript · Junior · Question 15 of 75
What does user?.address?.city return if user = {}?
- ✓Correct answer:
undefined - 2
TypeError - 3
null
Explanation
Optional chaining short-circuits and returns undefined if the value on the left is null or undefined. Without ?., user.address.city would throw a TypeError. There are also forms for calls fn?.() and indexes arr?.[0].