DEV Community

Discussion on: ES6 - Spread Operator

Collapse
 
bharatmhaskar profile image
Bharat Mhaskar • Edited

Example with optional chaining operator

let customer = {
name: "Carl",
details: {
age: 82,
location: "Paradise Falls" // detailed address is unknown

}
};
let customerCity = customer.details?.address?.city;

With spread operator
let { details: { address: {city: customerCity } ={}} = {} } = customer || {}