Hard20 minType Systems
UpdatedAug 1, 2026
Edit

Prototype Chain & new

CONCEPTS:JavaScript Closures

Question Variations

  • "What happens internally when you use the `new` keyword in JavaScript?"
  • "Explain the difference between `__proto__` and `prototype`."
  • "How does the prototype chain work when looking up a property on an object?"
  • "Can you implement a simple inheritance pattern using prototypes without the `class` keyword?"

Why This Is Asked

This separates developers who have surface-level ES6 class knowledge from those who understand JavaScript’s true inheritance model. Interviewers want to see if you can explain what new actually does under the hood and how the prototype chain resolves property lookups.

Key Concepts

  • JavaScript uses prototypal inheritance, not classical inheritance — objects inherit directly from other objects
  • Every object has a hidden [[Prototype]] link; property lookups walk this chain until null
  • new does four things: creates an empty object, links its prototype, executes the constructor with this bound, returns the object (unless the constructor returns a different object)
  • __proto__ is the object’s prototype link; .prototype is a property on functions used when they act as constructors
  • class syntax is syntactic sugar — it does not change the underlying prototype mechanism

Question Variations

  • “What happens internally when you use the new keyword in JavaScript?”
  • “Explain the difference between __proto__ and prototype.”
  • “How does the prototype chain work when looking up a property on an object?”
  • “Can you implement a simple inheritance pattern using prototypes without the class keyword?”

Answers by Technology

+ Add Variant
JavaScriptImprove this answer ✏️

Expected Answer

JavaScript uses Prototypal Inheritance. Every object has a hidden internal property (denoted as [[Prototype]]) that points to another object (its prototype). When you access a property that doesn’t exist on an object, the engine searches the prototype, then the prototype’s prototype, forming the Prototype Chain, until it hits null.

When using a constructor function with new, the new object’s [[Prototype]] is automatically linked to the constructor’s .prototype property.

Why It Matters

Understanding prototypes is key to understanding how JavaScript handles memory and inheritance. Instead of every instance having its own copy of a method, methods are shared on the prototype, saving significant memory. It also explains how built-in features like .map() or .filter() work—they are methods defined on Array.prototype.

Example Code

The new Keyword Mechanism

function Animal(name) {
  this.name = name;
}

Animal.prototype.sayHi = function() {
  console.log(`Hi, I'm ${this.name}`);
};

const dog = new Animal('Buddy');

// Steps during `new Animal('Buddy')`:
// 1. New object created: {}
// 2. Prototype linked: dog.__proto__ === Animal.prototype
// 3. `this` bound to new object: name = 'Buddy'
// 4. Object returned

Common Mistakes

  • Confusing __proto__ and prototype: prototype is a property on constructor functions used to build the chain for new instances. __proto__ (or Object.getPrototypeOf) is the actual link on an instance that points to its prototype.
  • Modifying Built-in Prototypes: “Monkey patching” (e.g., Array.prototype.myFunc = ...) is dangerous as it can cause collisions with future JS versions or other libraries.

Follow-up Questions

  • How does Object.create(null) differ from {}? (Answer: It creates an object with no prototype at all—no toString, no hasOwnProperty, etc. Useful for clean maps/dictionaries).
  • Does the class syntax change how this works? (Answer: No, class is mostly syntactic sugar over the same prototypal mechanism).

References