DEV Community

Discussion on: 10 Clean code examples (Javascript).

Collapse
 
sergei profile image
Sergei Sarkisian • Edited

So, if initially a has several properties

let a = { foo: 'some', bar: 'example' };
Enter fullscreen mode Exit fullscreen mode

Then after

c > d ? a.foo = 'apple' : a.bar = 'apple';
Enter fullscreen mode Exit fullscreen mode

a will have same amount of properties.
But after

a = { [c > d ? 'foo' : 'bar']: 'apple' };
Enter fullscreen mode Exit fullscreen mode

It will hav only 1 property. It's not even the same!