Object and prototype in javascript
Javascript object can be created with all or any data type of javascript. It is very easy to manipulate like add, update or delete. Getting data from object is very handy. It is core of javascript development.
Prototype — Predeclared property by javascript which gets attached to every new object. Very intrinsic feature of this is that child of ‘__proto__’ directly accessible by the object after getting attached to object which is not the object normal behaviour thus the behaviour is called as prototype inheritance.
The important point here is it providing features which makes the life easifier and curiosity to learn more.
Examples: obj.hasOwnProperty, obj.isPrototypeOf, obj.propertyIsEnumerable
This above example is to demostrate the property that get inherited when a new object is created.
Prototype chain refers and vary according to the nature of data type declared in javascript. For example array in javascipt contains a array prototype, which in itself contains the property object prototype which in itself contains a null prototype.
let a = [];
console.log(a.__proto__)
//[constructor: ƒ, at: ƒ, concat: ƒ, copyWithin: ƒ, fill: ƒ, …]
console.log(a.__proto__.__proto__)
//{constructor: ƒ, __defineGetter__: ƒ, __defineSetter__: ƒ, hasOwnProperty: ƒ, __lookupGetter__: ƒ, …}
console.log(a.__proto__.__proto__.__proto__)
//null
The array shown above inherited the property of array prototype, object prototype, and null prototype. Collectively we call them as prototype chain.