Mixed Bag Javascript

Encapsulation in JavaScript refers to the concept of bundling data (variables) and methods (functions) that operate on the data into a single unit, typically inside a class.
This is done to restrict access to certain parts of the object and protect its integrity by hiding its internal state (using private variables) and only allowing controlled access to the data.

We'll create a Person class that encapsulates a person's name and age. The name and age will be private and can only be accessed or modified through getter and setter methods.

Previous

                
              
Previous