8

https://github.com/lydiahallie/javascript-questions#14-all-object-have-prototypes All objects have prototypes, except for the base object. What is base object

gxr
  • 83
  • 1
  • 6
  • Possible duplicate of [How does JavaScript .prototype work?](https://stackoverflow.com/questions/572897/how-does-javascript-prototype-work) – Alex Jun 19 '19 at 05:28

1 Answers1

13

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.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320