JavaScript is a prototype-based language, but it also supports object-oriented programming (OOP) concepts through its class syntax.
- Object Literal: A simple way to create objects using
{}. - Constructor: A special method used to initialize objects.
- Prototype: An object that provides methods and properties to other objects.
- Classes: Blueprints for creating objects with shared properties and methods.
- Instances: Specific objects created from a class using the
newkeyword.
Definition: Hides complex implementation details and shows only the essential features. It simplifies interaction by providing a clear interface.
Example: A Car class that hides the complexity of starting the engine.
Definition: Bundles data and methods that operate on the data into a single unit (class) and restricts access to some components. It protects the internal state of the object.
Example: A BankAccount class that hides the balance and provides methods to deposit and withdraw money.
Definition: Allows a class to inherit properties and methods from another class. It promotes code reuse and establishes a hierarchy between classes.
Example: A Teacher class that inherits from a Users class, extending its properties and methods.
Definition: Allows objects to be treated as instances of their parent class, enabling method overriding and dynamic behavior. It enhances flexibility and method handling.
Example: An Animal class with different subclasses (Dog and Cat) where each subclass provides its own implementation of the speak method.
For a more detailed understanding of OOP concepts, you can watch this video.
abstraction encapsulation inheritance polymorphism