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.