https://github.com/lydiahallie/javascript-questions#14-all-object-have-prototypes All objects have prototypes, except for the base object. What is base object
The base object is Object.prototype
:
The
Object.prototype
is a property of the Object constructor. And it is also the end of a prototype chain.
console.log(Object.getPrototypeOf(Object.prototype));
Most objects inherit from some prototype, which may inherit from some other prototype, eventually ending at Object.prototype
.
console.log(
Object.getPrototypeOf(Function.prototype) === Object.prototype,
Object.getPrototypeOf(Number.prototype) === Object.prototype,
Object.getPrototypeOf(Object.getPrototypeOf(5)) === Object.prototype
);
That said, the text in your link isn't entirely accurate - it's possible to create objects which do not ultimately inherit from Object.prototype
, eg:
const obj = Object.create(null);
console.log(Object.getPrototypeOf(obj));
This can be done to avoid (probably unusual) name collisions for Object.prototype
methods, which can cause bugs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With