JavascriptWeb Design

What is OOP in Javascript?

Maybe you know, that javascript is not a class-based language like the other language. but still has ways of using object-oriented programing(OOP).

Javascript is a prototype-based programing language. It uses an object to get the other object’s properties.

OPP treats the data securely. It is not allowed to flow data freely. It is broken down the problem into small piece of objects to build data.

These are the features of Object-oriented programing in Js:

  • Class and Object
  • Encapsulation – reduce complexity+ increase reusability
  • abstraction – reduce complexity + isolate the impact of changes(hide details)
  • inheritance –  eliminate redundant code
  • Polymorphism – refactor ugly switch/case statement

Object:  object has a unique entity that contains properties and methods. we have a real-life example, A car has different characteristics like color, size, model, and type, and performs an action like driving.

Classes: A classes have many objects. because the class is a template and objects are instances. like another programing language, javascript does not have classes.

Encapsulation: It is the process of wrapping properties and methods in a single unit is known as encapsulation. it is hep to redux the complexity and increase the reusability of class or function.

Abstraction: It is the process of hiding the data is known as abstraction. means when we hide the details information about features in the background.

Inheritance: when we use another object’s properties and method as an object.

Polymorphism: When we have the same methods with different implementations in different classes is called polymorphism.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button