---
title: "How does prototypal inheritance work in JavaScript?"  
description: "How does prototypal inheritance work in JavaScript?"  
author: "Ravi Vishwakarma"  
published: 2024-06-17  
updated: 2024-06-17  
canonical: https://www.mindstick.com/interview/33910/how-does-prototypal-inheritance-work-in-javascript  
category: "javascript"  
tags: ["web development", "javascript", "front-end development"]  
reading_time: 2 minutes  

---

# How does prototypal inheritance work in JavaScript?

In JavaScript, objects can inherit properties from other objects via the prototype chain. Each object has a prototype, and if a property is not found on the object itself, JavaScript will look up the prototype chain to find it.

**Checking the Prototype Chain:** You can check an object's prototype using:

- **Object.getPrototypeOf(obj):** Returns the prototype of obj.
- **obj.__proto__:** Accesses the prototype of obj (non-standard, should be avoided in favor of **Object.getPrototypeOf)**.
- **instanceof:** Checks if an object is an instance of a constructor function.

```javascript
console.log(Object.getPrototypeOf(child) === parent); // true
console.log(child.__proto__ === parent); // true (non-standard way)
console.log(child instanceof Parent); // true (if using constructor function or class)
```

Prototypal inheritance provides a flexible and dynamic way to share properties and methods among objects in JavaScript, leveraging the prototype chain to enable reusability and efficient property lookup.

## Answers

### Answer by Ravi Vishwakarma

In JavaScript, objects can inherit properties from other objects via the prototype chain. Each object has a prototype, and if a property is not found on the object itself, JavaScript will look up the prototype chain to find it.

**Checking the Prototype Chain:** You can check an object's prototype using:

- **Object.getPrototypeOf(obj):** Returns the prototype of obj.
- **obj.__proto__:** Accesses the prototype of obj (non-standard, should be avoided in favor of **Object.getPrototypeOf)**.
- **instanceof:** Checks if an object is an instance of a constructor function.

```javascript
console.log(Object.getPrototypeOf(child) === parent); // true
console.log(child.__proto__ === parent); // true (non-standard way)
console.log(child instanceof Parent); // true (if using constructor function or class)
```

Prototypal inheritance provides a flexible and dynamic way to share properties and methods among objects in JavaScript, leveraging the prototype chain to enable reusability and efficient property lookup.


---

Original Source: https://www.mindstick.com/interview/33910/how-does-prototypal-inheritance-work-in-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
