Middle
Is it possible to create an object without a prototype in JavaScript?
sobes.tech AI
Answer from AI
Yes, in JavaScript, you can create an object without a prototype using the Object.create(null) method. Such an object does not inherit properties from Object.prototype, which is useful, for example, for creating pure dictionaries without conflicts with built-in methods.
const obj = Object.create(null);
obj.key = 'value';
console.log(obj.hasOwnProperty); // undefined
In this example, the obj object does not have the hasOwnProperty method because it lacks a prototype.