Open In App

How to Implement Object Oriented Programming in JavaScript ?

Last Updated : 30 Jan, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The concept of Object Oriented Programming in JavaScript was introduced in ES6. Before ES6 JavaScript did not support the OOPs and it was a completely functional-based programming language everything was done with the help of functions. We can implement the OOPs in ES6 by creating classes and their object instances. Now, after the introduction of ES6, JavaScript become an Object Oriented Programming language as it supports all four basic pillars of OOPs which are inheritance, encapsulation, abstraction, and polymorphism.

Example: The below code example will help you understand how you can implement Object Oriented Programming in JavaScript with the help of a class.

Javascript




class implementOOP{
    name = "GeeksforGeeks";
    getProp(){
        console.log(this.name);
    }
}
const obj = new implementOOP();
obj.getProp();


Output

GeeksforGeeks


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads