EasyType Coercion💻 Output Question

JavaScript Optional Chaining and Nullish Coalescing

💡

Hint

Consider how the code handles cases where properties are missing or null, and how the ?? operator provides a default value when the expression on its left is null or undefined.

What does this output?

let person = { name: 'John', address: { street: '123 Main St' } }
let unknownPerson = null
console.log(person.address?.street)
console.log(unknownPerson?.address?.street ?? 'Unknown')
console.log(person.phone ?? '(no phone)')

Correct Output

123 Main St
Unknown
(no phone)

Why this output?

More Type Coercion Output Questions

EasyPlus operator: string concat vs numeric addMediumLoose equality edge cases with nullEasytypeof for common valuesMediumTruthy and falsy — empty array and object are truthy

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz