Woah, this is elegant JavaScript


Woah, this is elegant JavaScript. Need to conditionally add a property to an object? Here's a slick approach.

The right-hand side is only applied if the condition is true. If the condition is falsy, the spread operator does nothing.

More: https://dev.to/jfet97/the-shortest-way-to-conditional-insert-properties-into-an-object-literal-4ag7

#javascript

View original on X