Last Updated : 11 Aug, 2025
Object Oriented Programming (OOP) is a style of programming that uses classes and objects to model real-world things like data and behavior. A class is a blueprint that defines the properties and methods an object can have, while an object is a specific instance created from that class.
Why OOP is Needed:
Before OOP, when the code size grows and multiple people work on a project, there problems arise
Object Oriented Programming (OOP) solves these problems by combining data and the functions that operate on it into a single unit called an object. This approach has following main features
In JavaScript, an object is a collection of data (properties) and actions (methods) stored as key–value pairs.
Objects let you group related data and functionality together in one place.
ClassesIn JavaScript, a class is a blueprint for creating objects with specific properties and methods. A class itself doesn’t hold values, it describes what an object should have and do. You create actual objects from a class using the new
keyword.
// Class definition
class Car {
constructor(brand, model) {
this.brand = brand; // property
this.model = model; // property
}
// method
showDetails() {
console.log(`This car is a ${this.brand} ${this.model}.`);
}
}
// Creating objects from the class
const car1 = new Car("Toyota", "Corolla");
const car2 = new Car("Honda", "Civic");
// Using the objects
car1.showDetails(); // This car is a Toyota Corolla.
car2.showDetails(); // This car is a Honda Civic.
Output:
This car is a Toyota Corolla.
This car is a Honda Civic.
Read:Abstraction
Abstraction is one of the key features of object-oriented programming in JavaScript. It means showing only the essential information and hiding unnecessary details from the user. Data abstraction refers to exposing only what is necessary to interact with the object while keeping the background details or internal logic hidden.
EncapsulationLearn here: Abstraction in JavaScript
Encapsulation is defined as wrapping up data and information under a single unit. In Object-Oriented Programming, encapsulation is defined as binding together the data and the functions that manipulate them together in a class.
InheritanceLearn here: Encapsulation in JavaScript
The capability of a class to derive properties and characteristics from another class is called Inheritance. Inheritance is one of the most important features of Object-Oriented Programming.
PolymorphismLearn here: JavaScript Inheritance
The word polymorphism means having many forms. In simple words, we can define polymorphism as the ability of an entity to behave different in different scenarios. person at the same time can have different characteristics.
Learn here: Polymorphism in JavaScript
These were all the essential OOP concepts in JavaScript, covering their complete mechanism and implementation. As OOP is an important part of JavaScript programming as it helps in building structured, reusable, and maintainable code. By using classes, objects, inheritance, polymorphism, encapsulation, and abstraction, developers can write cleaner programs that model real-world scenarios effectively while keeping the code easy to update and scale.
Introduction to Object Oriented Programming (OOPs)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4