Pages

Object-Oriented Programming in JavaScript

Understanding Classes and Objects in JavaScript:-

The OOPs concept stands for Object Oriented Programming. It is a programming language model organized around objects rather than "actions" and data rather than logic. OOPs is based on the concept of creating objects, which can hold data and functions. Objects are instances of classes, which are a blueprint for creating objects.


Object-oriented programming (OOP) is a programming language model organized around objects rather than "actions" and data rather than logic. An object can be defined as a data field that has unique attributes and behavior. Objects are used to interact with one another in order to accomplish tasks.

In Javascript, objects are created using the object constructor. This constructor creates an object with properties and methods that can be used to manipulate the object. Properties are the attributes of the object, such as its name, and methods are the functions that can be used to manipulate the object. Objects can also have other objects as properties, allowing for complex functionality.

Classes are the blueprints for creating objects. In Javascript, classes are created using the class keyword. They are used to define the properties and methods of an object. A class can also contain other classes, allowing for complex functionality.


Inheritance is a key feature of OOPs. It allows for classes to inherit the properties and methods of other classes. This allows for code reuse and easier maintenance.


The OOPs concept has been widely adopted by developers due to its flexibility and scalability. By using objects, classes, inheritance, encapsulation, polymorphism and abstraction, developers


Examples Of Oops:-

<script>

  //Example:1

  class Student{
  message(){
  console.log("hello javaScript");
        }
      }

  let obj=new Student();
  obj.message();

    //Example 2:-
       
    class cons{
    constructor(){
  console.log("consturctor parameter")
    }

    hello(){
    console.log("I am a Method");
       }
      }

   let object=new cons();
   object.hello();

   //Example:3rd

   class cons1{
   constructor(){
    let username;
   console.log
("i am example of constructor");
          }
    printname(username){
    this.username=username;
    console.log(this.username);
     }
        }

   let call=new cons1();
   call.printname("shivam");
           
    //Example:4

  class callings{
  constructor(name,age){
  this.name=name;
  this.age=age;
  console.log
("this is the example of constructor");
      }


display(){
console.log(`hello ${this.name}
Your Age is ${this.age}`);
        }
    }
   
let calls=new callings("shivam",30);
calls.display();
    </script>

No comments:

Post a Comment