1

Object:

    fruits {
      citrus {
        lime {
          id
        }
      }
      berries {
        ...
      }
    }

Destructuring fruits to reach lime:

const { citrus: { lime } = {} } = fruits;

My understanding is that if citrus is null, the destructuring will work and the value of lime will be an empty object {}. However this is not working. Am I missing something?

wazus
  • 103
  • 1
  • 7

1 Answers1

-1

You should do like this:

const { citrus = {} } = fruits;

or

const { citrus: { lime = {} } } = fruits;

but not how you showed it, it doesn't work like this

Evgeny Klimenchenko
  • 1,184
  • 1
  • 6
  • 15