JavaScript Internals (521 Qs)•Part 6: Async Internals, Memory, Microtasks & Web APIs (329 - 403)
Do all objects have prototypes
No. All objects have prototypes except two exceptions:
- Object.prototype itself — This is the base object in the prototype chain, and its prototype is
null. - Objects created with
**Object.create(null)**— These are deliberately created with no prototype, so they don’t inherit fromObject.prototype.
All other standard objects do have a prototype.
Practical Code Example
javascript
// Do ALL objects have prototypes?
// NO! Objects created with Object.create(null) have NO prototype:
const normalObj = {};
console.log(Object.getPrototypeOf(normalObj) === Object.prototype); // true
const bareObj = Object.create(null);
console.log(Object.getPrototypeOf(bareObj)); // null (No toString, valueOf, etc.)