Skip to content
Onsite

Output: destructuring with defaults where the value is undefined vs null

EasyP2Output

What does this code print?

1const { a = 1, b = 2, c = 3 } = { a: undefined, b: null };
2console.log(a, b, c);
3
4const [x = 'dx', y = 'dy'] = [undefined, null];
5console.log(x, y);
Saved automatically

One line per console.log. Arrays as [1, 2, 3], objects as { a: 1 }, an uncaught error as Uncaught TypeError: message (Chrome and Node wording).

Hints

Saved automatically