$ ./guess_the_languageProblem Solving — predict the output
Problem Solving — predict the output · medium · #247

What is the output?

const { a = 1, b = 2 } = { a: null, b: undefined };
console.log(a, b);
  1. 1 2
  2. null 2
  3. null undefined
  4. 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 ▸