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());