How to set default value in JavaScript’s Destructuring

Did you know that it's possible to set default value in Javascript object destructuring?
Let see how it works in action:
> { firstName = "John" } = {}
{}
> firstName
'John'
One thing to keep in mind is that it only works with undefined values. It won't work with null, false and 0 as these are normal values.
> { firstName = "John" } = { firstName: null }
{ firstName: null }
> { firstName = "John" } = { firstName: 0 }
{ firstName: 0 }
> {firstName = "John"} = { firstName: false }
{ firstName: false }
Work with a team that keeps learning and building better software every day.
Related posts
Dive deeper into this topic with these related posts
No items found.
You might also like
Discover more content from this category
Pattern-matching is one of the finest elixir-lang features. Whoever knows the power of this tool once, will want to use it forever.
Sometimes you may notice that your website displays an unintended horizontal scrollbar. You may be wondering what is the cause.
If you ever had to count occurrences of values in Elixir's list, this short post might be helpful for you!
