loading...

re: 5 Uses for the Spread Operator VIEW POST

TOP OF THREAD FULL DISCUSSION
re: What is the way you always use to prevent error when data is null or undefined? For my case, I always face this when 'initVar' is null or undefined...
 

Maybe you could actually use the spread to start with default values and override with initVar:

const { aaa: { bbb, ccc } } = {
  aaa: { 
    bbb: "default bbb", 
    ccc: "default ccc", 
    ...(initVar && initVar.aaa) 
  }
}

But not sure if that is really useful in maybe more complex deconstructions? :D

Code of Conduct Report abuse