DEV Community

Discussion on: Make your function calls more readable

Collapse
 
moopet profile image
Ben Sinclair

I like this.

I'm not so sure how I feel about

const { foo = 'foo' } = bar;

because it reads like assigning 'foo' to foo and then assigning bar.foo to foo to override it... but it's a const. I mean, I've tried it and it behaves like your const age = unicorn.age !== undefined ? unicorn.age : 5 example, but that's not what it looks like it should do. What's in the box, amirite?

Collapse
 
hamatti profile image
Juha-Matti Santala • Edited

I agree that the syntax for that is really confusing. Every time I write it, I have to check to make sure I'm putting things in the right place.

It gets even more confusing when you also rename properties:

const { foo: bar = 120 } = baz

What it does is essentially:

const bar = baz.foo === undefined : 120 ? baz.foo