GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing www.geeksforgeeks.org — Object Oriented Programming in JavaScript - GeeksforGeeks Object Oriented Programming in JavaScriptLast Updated : 10 Jul, 2026 Object-Oriented Programming (OOP) in JavaScript is a programming paradigm based on the concept of objects that contain data (properties) and behavior (methods). It focuses on designing software that closely represents real-world entities. It is used to:
Characteristics of OOPThe diagram below demonstrates the JavaScript OOP Concepts. ![]() ClassA Class in JavaScript is a blueprint or template used to create objects. It defines the properties (data) and behaviors (methods) that objects of that class will have.
Example: A Car represents a class (blueprint), while BMW, Mercedes, and Audi represent objects (instances) created from that class. ![]() ObjectAn Object in JavaScript is an instance of a class that represents a real-world entity. It is used to access the properties and methods defined inside a class.
Example: Dog is a class, Tommy is an object of that class. ![]() AbstractionAbstraction in JavaScript is the process of hiding implementation details and showing only the essential features of an object. It helps users focus on what an object does rather than how it does it.
Example: An ATM or a coffee machine represents abstraction, where the user interacts with simple operations while the internal implementation details remain hidden. ![]() How to Achieve AbstractionIt is achieved in JavaScript using classes, closures, modules, and private fields.
EncapsulationEncapsulation is the process of wrapping data and methods into a single unit and restricting direct access to the data. It acts as a protective shield that prevents data from being accessed directly from outside the object.
![]() InheritanceInheritance is a core OOP concept in JavaScript that allows one class to acquire the properties and methods of another class using the extends keyword. It represents an "is-a" relationship between classes.
Example: Dog, Cat, and Cow can be derived classes of the Animal parent class. ![]() Types of InheritanceJavaScript supports the following types of inheritance:
PolymorphismPolymorphism means "many forms", where a single entity can behave differently in different situations. In JavaScript, it allows the same method or object to show different behavior based on context.
Example: Different animals represent polymorphism, where the same method speak() produces different outputs like Bark, Meow, and Moo depending on the object. ![]() Types of PolymorphismPolymorphism in JavaScript is mainly of the following types:
AssociationAssociation is an OOP concept that defines a relationship between two or more objects that are connected to each other. It represents how objects interact with each other and communicate. In association, objects of one class are related to objects of another class, but they can exist independently.
Types of AssociationAssociation in JavaScript can be further classified into the following types: 1. Aggregation (Weak Association)Aggregation represents a "has-a" relationship where one object contains a reference to another object, but both can exist independently. Example: A Company has Employees, but employees can exist independently even if the company no longer exists. ![]() 2. Composition (Strong Association)Composition is a strong form of association where one object owns another object. If the parent object is destroyed, the child object also gets destroyed. Example: A House is composed of Rooms, and if the house is destroyed, the rooms cannot exist independently. ![]() Advantages of OOPObject-Oriented Programming (OOP) offers several key advantages over procedural programming:
Comment Explore |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |