Question 19
Back to Exercise
What does the following JavaScript code print (console output, as in Node.js)?
const target = { a: 1 };
const result = Object.assign(target, { b: 2 }, { a: 3 });
console.log(result === target, target);
- A false { a: 1 }
- B true { a: 3, b: 2 } Correct
- C true { a: 1, b: 2 }
- D false { a: 3, b: 2 }
Correct Answer: Option B
Object.assign copies into and returns its first argument. a keeps its original position but takes the last value, 3.
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!