When would you want to use Object.create(null) instead of {} to create a new object?
- When you need an object with no prototype chain to avoid inheriting properties or methods unintentionally.
- When you want an object that can't be modified or extended further.
- When you need an object with a predefined set of properties and methods for a specific use case.
- When you want to create an empty object with the default prototype chain.
Object.create(null) is used when you need an object with no prototype chain (a "null prototype"), which means it won't inherit any properties or methods from Object.prototype. This can be useful for creating objects where you want complete control over the properties and avoid unintentional inheritance.
Loading...
Related Quiz
- The property event.target gives access to the _________ that triggered the event.
- The ______ statement is used to specify a block of code to be executed if the condition is false.
- When you want to store multiple values in a single variable, you should use a(n) _________.
- You are refactoring a codebase and converting regular functions to arrow functions. In which of the following cases would you need to be most cautious about changing the function type due to the "this" keyword's behavior?
- Which of the following methods mutates the original array?