One of the drawbacks of creating a true private method in JavaScript is that they are highly memory consuming. A new copy for each method is created for every instance.

Example:

var Employee = function (name, company, salary) {
    this.name = name || "";
    this.company = company || "";
    this.salary = salary || 5000;
    var increaseSlary = function () {
        this.salary = this.salary + 1000;
    };
    this.dispalyIncreasedSalary = function() {
       increaseSalary();
       console.log(this.salary);
   };
};
var emp1 = new Employee("Amar","Mars",3000);

Here, while creating each variable, each instance makes a new copy of emp1, emp2, and emp3 in IncreaseSalary. Thus, making it inefficient for your server end.

BY Best Interview Question ON 20 Jun 2020

Suggest An Answer