Your product could be here, in front of thousands of JavaScript developers. Sponsor this spot →
JavaScript Quiz

How does optional chaining short-circuit in JavaScript?

Do you know what will be the output of this code?

JavaScript
const user = {};
console.log(user.profile?.name.first);
Show answer and explanation

The answer is undefined.

user.profile is undefined, so ?. stops the whole expression right there. .name.first is never evaluated, so there’s no error.

Take the full quiz Next question →

More Objects questions

  1. Does the spread operator make a deep copy?
  2. When do default parameters apply in JavaScript?
  3. What is the difference between ?? and || in JavaScript?
  4. When do destructuring default values apply?
  5. How do you swap two variables with destructuring?

Related topics