The closest I get in Javascript was to use the || operator. Using it on multiple operand will result in taking the first non null, non undefined, non false variable. See done below:
const a = null; const b = false; const c = 8; a || b || c; 8 const d = true; a || d || c; true const e = undefined; a || e || c; 8
Cool!
ReplyDeleteIn python we can use or
ReplyDeletea=None
b=False
c=8
a or b or c gives 8
In Java I would go with Stream.of(...).filter(...).findFirst()...
ReplyDeleteOr apparently there is a method firstNonNull in Apache Commons Lang 3 but it is only for null check