// option 1
let val = a.b.c.d || null;
// this gives error if a.b.c is undefined or a.b is undefined etc.
// option 2: alternate version
let val2 = null;
if (a.b && a.b.c && a.b.c.d) {
val2 = a.b.c.d;
}
Is there an elegant way of writing the above code that is somewhat similar to option 1?