I am using short circuit evaluation to set a key in an object. For example:
var obj = {foo : 'bar'}
var obj2 = {}
obj2.somekey = obj.baz || obj.foo //will assign 'bar' to obj2.somekey
The only difference with my code from that above, is that instead of assigning obj.foo if obj.baz doesn't exist, I would like obj.somekey to stay undefined. I tried obj2.somekey = obj.baz ||
, but it threw me a syntax error.
Note that null
and undefined
, as this question suggests, are not actually undefined either.
So is there any way I can do this with short circuit syntax?