Destructuring & Spread Operator
What happens when you destructure a property that doesn't exist on the object?
When you destructure a property that doesn't exist on the object, the variable is assigned the value `undefined`. This is consistent with how JavaScript handles property access: attempting to access a non-existent property on an object returns `undefined`. For example, in `const { nonExistent } = { existing: 42 };`, the variable `nonExistent` will be `undefined`. This behavior allows for flexible destructuring patterns where you might not be certain if all properties exist. To handle this gracefully, you can provide default values in the destructuring pattern: `const { nonExistent = 'default' } = obj;`. With a default value specified, if the property doesn't exist or is `undefined`, the variable will be assigned the default value instead. This default value assignment only applies to `undefined` properties, not to other falsy values like `null`, empty strings, or zero.