Gentle Introduction to Prototypes and Prototypal Inheritance in Javascript

In this short video tutorial I will explain in simple terms what are prototypes in Javascript and how Inheritance works.

Key points to keep in mind

  • In Javascript if an object wants to inherit from another object then it can do so using prototypal inheritance.
  • The parent object is referred to as Prototype.
  • __proto__ is deprecated, we can use Object.create()
let fourWheelerObj = {tyres: 4} // Prototype

let carObjectOne = {engine: 'v6', __proto__: fourWheelerObj}

console.log(carObjectOne.tyres) // 4


let carObjectTwo = Object.create(fourWheelerObj)
console.log(carObjectTwo.tyres) // 4