LearnFrenzy
Sign in Take a free test

Objects · Predict the Output · Question 19

What Object.assign returns Answer, explanation & discussion

  • Output
  • Medium
  • 0 comments
  • Answer explained
  • Moderated community
Question 19 Back to Exercise

What does the following JavaScript code print (console output, as in Node.js)?

main.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!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links