Javascript: What is the difference between prototype and __proto__ in JavaScript? | Interview Question

the only true difference between prototype and __proto__ is that the former is a property of a class constructor, while the latter is a property of a class instance.

The prototype is an object that is associated with every functions and objects by default in JavaScript, where function’s prototype property is accessible and modifiable and object’s prototype property (aka attribute) is not visible.

Every function includes prototype object by default.

prototype is a property of class/function A.

See the below example

Example,
function A() {}; // constructor

// faceID and video are methods of constructor function A
A.prototype.faceID = function() { … };
A.prototype.video = function() { … };

lets look into another example of prototype, age is a property of prototype of Student class.

__proto__ is internal property of an object, pointing to its prototype.

lets look into example of __proto__,

function A() {}; // constructor

// newPhone is instance of class A and it has property __proto__.
let newPhone = new A();

let’s look into another example of __proto__, so in the below example we can see __proto__ points to its (Person) prototype.

Summary

  • prototype is a property of class/function A
  • __proto__ is internal property of an object, pointing to its prototype.
  • prototype is an object that is associated with every functions and objects
  • Every function includes prototype object by default

--

--