How to do optional chaining in JS ES6 for this?

Viewed 18

I have this nested and ugly working code which I want to simplify. I want to make it cleaner without throwing any error if a value is missing. Anyone can suggest a cleaner way to do this?

const addressId =
  customer &&
  customer.addresses &&
  customer.addresses[0] &&
  customer.addresses[0].id
0 Answers
Related