Question 8
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const [a = 1, b = a * 2] = [];
const { x = 3, y = x + 1 } = { x: 10 };
console.log(a, b, x, y);
- A 1 2 3 4
- B 1 NaN 10 11
- C 1 2 10 11 Correct
- D undefined undefined 10 11
Correct Answer: Option C
A default may use variables that appear earlier in the same pattern. y's default uses the x that was actually received (10).
Discussion & Comments 0
Share your method, a shortcut, or ask about a step you didn't follow.
No comments yet. Be the first to share your solution!