re: 5 Uses for the Spread Operator VIEW POST


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. Or at lease 'aaa' is null or undefined.

const {aaa: {bbb, ccc}} = initVar


So that example is desrructhring assignment. I look at that in a different post which is linked at the bottom of this one.


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