What is the output?
const { a = 1, b = 2 } = { a: null, b: undefined };
console.log(a, b);
- 1 2
- null 2
- null undefined
- 1 undefined
Destructuring defaults apply only when the value is undefined. null is a real value, so a stays null while b falls back to 2.
Play Problem Solving ▸