Primarily an es6/7 question dealing with object destructuring.
Suppose I have this sample function:
const sample = (var1, var2) => {
const obj = {
one: var1
};
if (var2) {
obj.two = var2;
}
return obj;
};
Its a way of saying, "the first argument is expected, if the 2nd argument is defined add it to the object too".
Is there a more elegant way to achieve the same effect but with object destructuring?