Destructuring Defaults
Defaults apply when the property is undefined — not when it is null, 0, or "".
Defaults apply when the property is undefined — not when it is null, 0, or "".
const { a = 1, b = 2 } = { a: undefined, b: null };
// a = 1 (undefined triggers default), b = null (null does not)
const [x = 10, y = 20] = [5];
// x = 5, y = 20
// Combining rename, default, and nesting:
const { config: { theme = "light", lang = "en" } = {} } = settings;
null does not trigger defaults — only undefined does. Plan accordingly.
More in JavaScript