Encapsulation in JavaScript

 

Hi friend in this article I am going to describe what exactly encapsulation and emplemation in JavaScript

In a simple word encapsulation is defined as the wrapping up of data and method under a single unit.

 

Example

class Person {

  constructor(name, phone, email) {
    this.name = name;
    this.phone = phone;
    this.email = email;
  }

  getPersonName() {
    return this.name;
  }

  getPersonPhone() {
    return this.phone;
  }

  getPersonEmail() {
    return this.email;
  }

}

const ob = new Person("Mahbub Hasan", 88021344444, "example@gmail.com");
console.log(ob.getPersonName());
console.log(ob.getPersonPhone());
console.log(ob.getPersonEmail());

 

About Author

Photo

Hi, I am Mahbub Hasan
Software Engineer

I am very much interested to share my programming
and development knowledge with the people.I will try
to update my blog everyday with new technology inshallah.

Thank You

For Visiting My Blog.

Contact Me