AI

Optional Chaining (?.) allows you to access deeply nested properties without worrying if an intermediate property is null or undefined. Accessing a missing property simply returns undefined instead of throwing an error.

Your Task:

  • You have a user object that might have a missing profile or address
  • Safely extract the zipCode from user.profile.address.zipCode into a variable zip
  • Safely call a method user.getDetails?.() (it might not exist!) and store in details
TypeScript Solution
Loading...

Submit your code to see test results