In Javascript all objects have prototypes, except for the base object
Solution 1:
The vast majority of objects you'll encounter ultimately inherit from Object.prototype
. This includes built-in objects and objects created with object literal syntax, among many others.
const obj = {};
console.log(Object.getPrototypeOf(obj) === Object.prototype);
A very few objects, including Object.prototype
itself, do not inherit from anything. This will only occur if the object is explicitly created with Object.create(null)
.
console.log(
Object.getPrototypeOf(Object.prototype) === null,
Object.getPrototypeOf(Object.create(null)) === null
);