0

I have two javascript variables.

  const var1 =
    obj1 &&
    obj1.auth &&
    obj1.auth.p_id;

  const var2 =
    obj1 &&
    obj1.auth &&
    obj1.auth.semi &&
    obj1.auth.semi.y_id;

Only of the above variables var1 and var2 will have a value.

I need to eventually fill it inside another variable.

someObj.property1 = var1 or var2 depending upon which one has values.

How can i refactor it so that either var1 or var2 does not throw an object reference error?

user2281858
  • 1,777
  • 9
  • 33
  • 69

0 Answers0