1.
Which of the following methods is used to add a new property to an object in JavaScript?
Object.assign()
Object.defineProperty()
Object.create()
Object.keys()
Correct: A, B
The Object.assign() method is used to copy the values of all enumerable properties from one or more source objects to a target object. It can also be used to add new properties to an object. The Object.defineProperty() method, on the other hand, is used to add a new property or modify an existing property of an object, and it allows for more fine-grained control over the property's attributes.
1 / 30