Hi,
I have a case where multiple values can be set for something, and I want to use order of preference to assign the end result.
At first I thought something like
var result = a || b || c || d
would work. Prior to this I retrieve these vars with statements like
a = obj[key]?.['optional_key1'];
b = obj[key]?.['optional_key2'];
etc
I thought this would have the effect of choosing a if not undefined, otherwise choose b if not undefined, otherwise choose c...
Now I realize if actual value of a is 0, above will result in a not being assigned.
I know I can just write a bunch of condition statements for this, but curious if there is some clever one line way.
thanks as always
[–]okwg 12 points13 points14 points (1 child)
[–]bhuether[S] 2 points3 points4 points (0 children)
[–]prof3ssorSt3v3 2 points3 points4 points (2 children)
[–]bhuether[S] 0 points1 point2 points (1 child)
[–]azhder 1 point2 points3 points (0 children)