---
title: Prototype Inheritance in JavaScript
description: Javascript uses a prototypal inheritance model and this can be a little confusing for developers coming from class-based languages like Java or C++. In this post, we are going to talk about this type of inheritance and how it is built in JS.
image: https://blog.avenuecode.com/hubfs/js.png
---

[AvenueCode.com](https://avenuecode.com) [News](https://avenuecode.com/news) [Contact](https://avenuecode.com/contact)

[![Avenue Code Snippets Logo](https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/AC-Snippets---Black.png)](https://blog.avenuecode.com/?hsLang=en-us) *menu*

- Technology
  
  [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us) [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us) [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us) [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us) [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
  
  [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us) [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us) [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us) [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

- [Cloud](https://blog.avenuecode.com/blog/topic/cloud?hsLang=en-us)
- [Design](https://blog.avenuecode.com/blog/topic/design?hsLang=en-us)
- [Delivery Infrastructure](https://blog.avenuecode.com/blog/topic/delivery-infrastructure?hsLang=en-us)
- [Solution Architecture](https://blog.avenuecode.com/blog/topic/solution-architecture?hsLang=en-us)
- [Web Experience](https://blog.avenuecode.com/blog/topic/web-experience?hsLang=en-us)
- [Data & ML](https://blog.avenuecode.com/blog/topic/data-and-machine-learning?hsLang=en-us)
- [Agile Mindset](https://blog.avenuecode.com/blog/topic/agile-mindset?hsLang=en-us)
- [Mobile Experience](https://blog.avenuecode.com/blog/topic/mobile-experience?hsLang=en-us)
- [Quality First](https://blog.avenuecode.com/blog/topic/quality-first?hsLang=en-us)
- [Whitepapers](https://blog.avenuecode.com/blog/topic/whitepapers?hsLang=en-us)
- [Spotlight](https://blog.avenuecode.com/blog/topic/spotlight?hsLang=en-us)
- [Extraordinary Women in Tech](https://blog.avenuecode.com/blog/topic/extraordinary-women-in-tech?hsLang=en-us)
- [Avenue Code Culture](https://blog.avenuecode.com/blog/topic/avenue-code-culture?hsLang=en-us)

# [Prototype Inheritance in JavaScript](https://blog.avenuecode.com/prototype-inheritance-in-javascript)

- [Tweet](https://twitter.com/share)

*perm\_identity* [Rafael Bicalho](https://blog.avenuecode.com/prototype-inheritance-in-javascript/author/rafael-bicalho?hsLang=en-us)

*schedule* 3/6/19 3:00 PM

JavaScript uses a prototypal inheritance model, and this can be a little confusing for developers coming from class-based languages such as Java or C++. Prototype inheritance is simple but yet a powerful model. In this post, we are going to talk a little bit about it and how it is built in JS. If you haven't used a prototypical model before, don't be intimidated - we'll break it down!

Each JS object has a property called `[[Prototype]]`, which holds a link to another object referred to as the object's prototype. This prototype object has its own prototype, and so on and so forth. When trying to access a property of an object, JavaScript will look at the object itself first. If it doesn’t find the property, it looks in that object's prototype. If it doesn’t find it in the prototype, it looks in the prototype of the prototype, and so on until a property with a matching name is found or until it reaches an object with `null` as its prototype, meaning that the prototype chain is over.

The `[[Prototype]]` property is accessed using the accessors `Object.getPrototypeOf()` and `Object.setPrototypeOf()`. It can also be accessed via the property `__proto__`, which is non-standard but implemented by many browsers. For the sake of simplicity, we’re going to use `__proto__`from now on in this article, as shown below:

Note that the code above is merely a simplified version of the following: 

`Object` is called a constructor function, which is a function used to create objects. (If you want to learn more about the different ways we can create objects and the resulting prototype chain of each method, be sure to read next week's Snippet on Object Creation in JavaScript.)

In JavaScript, functions have a special property called "prototype" (not to be confused with the object property `__proto__`), and this is used when the function is called with the `new` keyword in order to set the prototype of the object being created.

In fact, if we check the value of `Object.prototype,` we get the same result as the `x.__proto__`. 

To make things clear, let's look at another example. First, we’ll create a function called “Person.” This will be our constructor function, and in JavaScript, the first letter of a constructor function is capitalized by convention. 

As we’ve seen before, `Person` has a property called `prototype`. So we are going to create a function called `greetings` inside of it:

Now we’ll create an object using our constructor function: 

If we check `johnDoe.__proto__`, we will see our `greetings` function there. When we call `johnDoe.greetings()`, the interpreter will check johnDoe’s properties. Since the function is not defined there, it will check its prototype (referenced by the `__proto__` function), and then we’ll get the expected result:

Now, let's find out what happens if we create our object and then change our constructor function after that, like this:

What do you think will be the output? … If you said “Hello! =),” you are correct! This is because, as we said before, the `__proto__` property is a reference to the object’s prototype and not a copy of it. You can also check that `johnDoe.__proto__ === Person.prototype` is `true`, meaning that both properties point to the same place.

Happy coding!

 

---

[![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Blog/linkedin.png)](https://www.linkedin.com/in/rbika/)

### Author

# Rafael Bicalho

 Rafael Bicalho is a UI Engineer at Avenue Code. He is a fan of technology, coffee and programming.

---

### Related Posts

### \[JAVA 21\] Structured Concurrency: Powering Data Orchestration with Virtual Threads and Scopes

[READ MORE](https://blog.avenuecode.com/java-21-structured-concurrency-powering-data-orchestration-with-virtual-threads-and-scopes?hsLang=en-us)

### How to Build Unit Tests Using Jest

[READ MORE](https://blog.avenuecode.com/how-to-build-unit-tests-using-jest?hsLang=en-us)

### How to Create Your Own RAR Extractor Using Electron

[READ MORE](https://blog.avenuecode.com/how-to-create-your-own-rar-extractor-using-electron?hsLang=en-us)

### How to Create a Tic-Tac-Toe Board Using React.js

[READ MORE](https://blog.avenuecode.com/how-to-create-a-tic-tac-toe-board-using-react.js?hsLang=en-us)

### Leave a Comment!

### Avenue Code Social

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Blog/facebook.png?t=1486470796564)](https://www.facebook.com/avenuecode)

[![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Blog/twitter.png?t=1486470796842)](https://twitter.com/AvenueCode)

[![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Blog/linkedin.png?t=1486470796556)](https://www.linkedin.com/company/avenue-code)

### Newsletter

Want to stay on top of all tips and news from Avenue Code?

### Popular Snippets

![Primary Logo AvenueCode Inverted.png](https://blog.avenuecode.com/hs-fs/hubfs/Images/Logos/Primary%20Logo%20AvenueCode%20Inverted.png?width=1104&name=Primary%20Logo%20AvenueCode%20Inverted.png "Primary Logo AvenueCode Inverted.png")

### About Us

- [Who We Are](https://www.avenuecode.com/who-we-are)
- [What We Do](https://www.avenuecode.com/what-we-do)
- [Portfolio](https://www.avenuecode.com/portfolio)
- [Partners](https://www.avenuecode.com/partners)
- [News](https://www.avenuecode.com/news)
- [Events](https://www.avenuecode.com/events)
- [Blog](https://blog.avenuecode.com/)
- [Contact](https://www.avenuecode.com/contact)

### Our Offices

San Francisco

[+1 415 766 4178](tel:+553125161448) [ac.inquiries@avenuecode.com](mailto:brazil.info@avenuecode.com)

Belo Horizonte

[+55 31 2516 1448](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

São Paulo

[+55 11 3205 3232](tel:+553125161448) [brazil.info@avenuecode.com](mailto:brazil.info@avenuecode.com)

### We're Hiring!

- [Belo Horizonte](https://www.avenuecode.com/who-we-are)
- [New York](https://www.avenuecode.com/what-we-do)
- [San Francisco](https://www.avenuecode.com/portfolio)
- [São Paulo](https://www.avenuecode.com/partners)

---

©2015 - 2017 Avenue Code

[![Facebook Icon](https://blog.avenuecode.com/hubfs/Images/Icons/facebook-2.png)](https://www.facebook.com/avenuecode) [![Twitter Icon](https://blog.avenuecode.com/hubfs/Images/Icons/twitter-2.png)](https://twitter.com/AvenueCode) [![LinkedIn Icon](https://blog.avenuecode.com/hubfs/Images/Icons/linkedin-2.png)](https://www.linkedin.com/company/avenue-code) [![Glassdoor Icon](https://blog.avenuecode.com/hubfs/Images/Icons/glassdoor-icon-1.png)](https://www.glassdoor.com/Overview/Working-at-Avenue-Code-EI_IE456173.11,22.htm) [![YouTube Icon](https://blog.avenuecode.com/hubfs/Images/Icons/youtube-2.png)](https://www.youtube.com/user/AvenueCodePlay)

Please enable JavaScript to view the [comments powered by Disqus.](http://disqus.com/?ref_noscript)

© 2026 Avenue Code

```json
{
  "@context" : "https://schema.org",
  "@type" : "BlogPosting",
  "author" : {
    "@type" : "Person",
    "name" : "Rafael Bicalho",
    "url" : "https://blog.avenuecode.com/author/rafael-bicalho"
  },
  "dateModified" : "2019-03-06T18:00:05.921Z",
  "datePublished" : "2019-03-06T18:00:00.000Z",
  "headline" : "Prototype Inheritance in JavaScript",
  "image" : [ "https://blog.avenuecode.com/hubfs/js.png" ],
  "mainEntityOfPage" : {
    "@id" : "https://blog.avenuecode.com/prototype-inheritance-in-javascript",
    "@type" : "WebPage"
  },
  "publisher" : {
    "@type" : "Organization",
    "logo" : {
      "@type" : "ImageObject",
      "url" : "https://blog.avenuecode.com/hubfs/Avenue%20Code%20New%20Logos%20-%202023/Avenue%20Code-primary%20versions_LOGO%20HORIZONTAL%20group%201-7.png"
    },
    "name" : "Avenue Code"
  }
}
```