Conditional object properties

Luke Mitchell luke at
Wed Nov 2 12:18:37 UTC 2016

Hi all,

I often come across a situation where I wish to extend an object
(usually an argument for an API request) if a particular condition is
satisfied, such as the presence of a function parameter. Currently the
only way to do this is by assigning the object to a variable, checking
the condition using an `if` statement and then extending the object. I
am proposing the inclusion of an operator that allows a property to be
included, subject to a particular condition, inside the object

The operator looks like this:

let obj = {
  cond ? prop: value


The operator could also be used with a block statement, allowing
multiple properties to be included:

let obj = {
  cond ? {
    prop1: value1,
    prop2: value2

I have created a draft proposal and would love to hear any thoughts
you have on the matter. You can find it on my GitHub, at the link

Kind regards,

More information about the es-discuss mailing list