Did you know that it's possible to set default value in Javascript object destructuring?

Table of contents

    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 }
    Szymon Soppa Web Developer
    Szymon Soppa Curiosum Founder & CEO

    Read more
    on #curiosum blog

    Bringing SOLID to Elixir

    Bringing SOLID to Elixir

    The SOLID principles, originally designed for object-oriented programming, can also be adapted effectively to functional programming languages like Elixir. Read how to apply it to create more maintainable, scalable, and adaptable software systems.