Question 7
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const a = { n: 1, d: { x: 1 } };
const b = { ...a };
b.n = 2;
b.d.x = 2;
console.log(a.n, a.d.x);
- A 2 2
- B 1 1
- C 2 1
- D 1 2 Correct
Correct Answer: Option D
n is copied by value into b; d is a reference to the same nested object, so b.d.x = 2 is visible through a.
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!