DEV Community

Discussion on: Destructuring JavaScript objects like a pro

Collapse
 
js2me profile image
Sergey S. Volkov • Edited

Good article, thanks ! :)

But one moment

We have small but important difference between default value of destructed property and ||

const { foo = "bar" } = baz

In this case runtime compiler (as I know) checks value only on undefined and because of this some falsy value like false or '' is not been replaced to default value "bar"

But in other case

const foo = baz.foo || "bar"

|| checks first operand on any possible falsy value and if we have .foo like null then variable will been equals to "bar"