JavaScript is a dynamic language and at any time we can add new properties to an object and can be shared among all the instances. Hence to add new properties and implement inheritance prototypes are used.


function Candidate() { = 'Arun';
    this.role = 'QA';
var candidateObj1 = new Candidate();
candidateObj1.salary = 10000;
console.log(candidateObj1.salary); // 10000
var candidateObj2 = new Candidate();
console.log(candidateObj2.salary); // undefined

Prototype in JavaScript
A prototype is an internal object that is associated with the functions automatically it is available, modified, or add additional variables or methods for it, and then share across all functions of their constructor.
BY Best Interview Question ON 25 Aug 2022

Suggest An Answer