What is the purpose of the Object.assign() method in JavaScript?

What is the purpose of the Object.assign() method in JavaScript?

a) To merge multiple objects into one
b) To copy properties from one object to another
c) To compare two objects
d) To delete properties from an object

Answer:

b) To copy properties from one object to another

Explanation:

The Object.assign() method is used to copy the properties from one or more source objects to a target object. It returns the target object with the combined properties. This is useful for shallow copying or merging objects.

Reference:

JavaScript MCQ (Multiple-Choice Questions)

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top