JavaScript · Junior · Question 15 of 75

What does user?.address?.city return if user = {}?

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].

Further reading

Problem with a question

JavaScript · Junior · question 15

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz