Izac Wiki

OOP

Object Oriented JavaScript

Object Oriented Programming is a programming paradigm that uses objects and their interactions to design applications and computer programs.

Object

An object is a key having a value. The value can be a primitive data type, a function, or an object. The key is always a string, but the value can be anything.

      
        
let person = {
name: "John",
age: 30,
hobbies: ["reading", "music", "movies"],
greet: function() {
console.log("Hello, World!");
}
};

Class

A class is a blueprint for creating objects. It defines the properties and methods that an object can have.

      
        
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log("Hello, World!");
}
}

Instance

An instance is an object that is created from a class. It has all the properties and methods that were defined in the class.

      
        
let person = new Person("John", 30);

Inheritance

Inheritance is a mechanism that allows a class to inherit properties and methods from another class.

      
        
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
greet() {
console.log("Hello, World!");
}
}
class Student extends Person {
constructor(name, age, grade) {
super(name, age);
this.grade = grade;
}
study() {
console.log("Studying...");
}
}