DEV Community

Discussion on: ES6 - Spread Operator

Collapse
 
bharatmhaskar profile image
Bharat Mhaskar

I think you should also cover "The optional chaining operator (?.)" as spread operator is used to accessing deeper values in objects with safe defaults.

Collapse
 
skaytech profile image
skaytech

Could you provide an example of how it's related to the spread operator?. Or is it used along with spread operator? I'm not quiet sure how to relate that with the 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 || {}