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
var1orvar2does not throw an object reference error?