Closed
Description
Perhaps there is a good reason for this but I never understood why the compound assignment ||= is not part of js. This would be helpful to ensure a variable to be defined.
Given:
let a = {"key":"value"}
This would let us write:
a.key ||= "default";
a.anotherKey ||= "anotherDefault";
Instead of
a.key = a.key || "default";
a.anotherKey = a.anotherKey || "anotherDefault";
Of course we could have used
a = {...a, key:"default", anotherKey:"anotherDefault"}
But as a general case, this should work on any variable
let a;
a ||= "default";
instead of
let a;
a = a ||"default";