3 ms·
You can avoid the SyntaxError by abusing boolean expressions a bit: > obj = {} {} > obj != null && (obj.bar = 42) 42 > obj { bar: 42 } Not as pret
by nuxi 2y ago
You can avoid the SyntaxError by abusing boolean expressions a bit:
> obj = {}
{}
> obj != null && (obj.bar = 42)
42
> obj
{ bar: 42 }
Not as pretty as your LHS case, but it works.
- Wingy 2y agoWith the length of that you might as well do: if (obj) obj.bar = 42