Data Encapsulation in ES5

This lesson explains the steps to protect properties and teaches how to access these protected properties.

Hiding Data

Till now, all the constructor function properties were easily accessible outside of it, and their values could easily be modified without any restrictions. In JavaScript, both ES5 and ES6 versions, there is no formal support for access modifiers using keywords such as public, private or protected. By default, all the properties are public; hence, can easily be accessed.

Let’s discuss property protection for ES5 version. We will look at the ES6 version later on in the course.

Before we get into the details, let’s take a look at the ...

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy