What gets logged?
const { x = 5 } = { x: null };
console.log(x);
- 5
- null
- undefined
- TypeError
0
voters
What gets logged?
const { x = 5 } = { x: null };
console.log(x);
It logs null — the default only applies when the property is undefined, not when it’s present-but-null.
const { x = 5 } = { x: null };
console.log(x); // null
JS Quiz answer: Option 2 (B).
Correct choice: null
Why:
Destructuring defaults apply only when the value is undefined, not null.
Go deeper:
Interesting
:: Copyright KIRUPA 2024 //--