Which method would you use to add a new property to an object after it has been created?
- Object.add()
- Object.append()
- Object.assign()
- Object.insert()
To add a new property to an existing object in JavaScript, you would typically use the Object.assign() method. This method allows you to merge properties from one or more source objects into a target object. It can be used to add or update properties in the target object.
Loading...
Related Quiz
- In a UI with nested dropdown menus, a developer wants to ensure that clicking a nested menu item does not trigger the click event of its parent menu. What method can be used to stop the event from reaching the parent menu?
- Which array method adds elements to the beginning of an array?
- What is the impact on performance when using a switch statement versus multiple if-else statements for numerous conditions?
- In a Node.js application, you need to perform several database operations consecutively, where each operation depends on the result of the previous one. How might you structure your asynchronous code to handle this scenario efficiently?
- How does the temporal dead zone impact function expressions in JavaScript?