If I want to set a constant with a value from a nested object property that can be undefined or set it to a default value, I can do this:
const a = b && b.c && b.c.d ? b.c.d : "default value";
I don't like this syntax because I find it unreadable. I prefer:
const a = b.c.d || "default value";
But this syntax fails if b
or c
is not an object (undefined). Is there a syntax for this kind of need?