# Conditionally add properties to objects in JavaScript

> Conditionally add properties to objects in JavaScript. This comes in handy when you want to completely omit a property from an object.

- URL: https://graffino.com/til/conditionally-add-properties-to-objects-in-javascript
- Author: Nick Ciolpan
- Channel: javascript
- Published: 2021-10-24
- Updated: 2024-04-13

This comes in handy when you want to completely omit a property from an object in case the value is undefined or null. 

```js
{prop1, prop2, ...(condition && prop3)}
```

The trick being here: 

```js
...(condition && prop3)
```

In case the ```condition``` evaluates to false, the property will be completely omitted from the object, otherwise, both the value and its corresponding key will show up in the end result.
