// 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;
}

是否有一种优雅的方式来编写上面的代码,有点类似于选项1?