How can you add a new property to a JavaScript object
- a) By using the Object.assign() method.
- b) By using the Object.addProperty() method.
- c) By simply assigning a value to a new property name.
- d) By using the addProperty() function.
You can add a new property to a JavaScript object by simply assigning a value to a new property name. For example, myObject.newProperty = 'some value';. While you can use methods like Object.assign() to copy properties from one object to another, it's not used for adding new properties. There's no Object.addProperty() or addProperty() method.
Loading...
Related Quiz
- You're refactoring your code to improve performance and notice a function that returns another function, accessing variables outside of its own scope. What specific JavaScript concept should you consider when optimizing this code section?
- What is the significant difference between Java and JavaScript?
- You have a block of code that needs to be executed when multiple conditions are true. Which control structure should be used to optimize the code for readability and performance?
- What is the main difference between stopPropagation and stopImmediatePropagation?
- What issues might arise due to JavaScript's prototype chain, and how might they be mitigated?