I want to include a property on an object only in the event that a variable is defined. I don’t want the property at all otherwise. I don’t even want it to equal a blank string. I’m thinking something like this:
someFunc({
bing: "bing",
bang: (myVar) ? myVar : undefined,
boom: "boom"
}, "yay");
In the event that myVar is undefined, I want this to result in the same thing as the below:
someFunc({
bing: "bing",
boom: "boom"
}, "yay");
Am I doing it right?
There is a difference between this:
and this:
Therefore, here’s how I would do it: