Question 6
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const o = { a: 1, ...{ a: 2, b: 3 }, b: 4 };
console.log(o);
- A { a: 1, b: 3 }
- B { a: 1, b: 4 }
- C { a: 2, b: 4 } Correct
- D { a: 2, b: 3 }
Correct Answer: Option C
Properties are applied left to right: the spread overwrites a with 2, then the literal b: 4 overwrites b.
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!