OOP (Object-Oriented Programming)Method Overloading and Overriding

Method overloading happens when multiple methods in the same class have the same name but different parameters. This lets you use the same method for different tasks depending on the input. Method overriding happens when a child class provides a different implementation of a method that already exists in the parent class. Overloading adds flexibility inside a class, while overriding helps tailor behavior in child classes without changing the parent class code.

// Overriding Example
class Parent {
  greet() {
    console.log('Hello from Parent');
  }
}
class Child extends Parent {
  greet() {
    console.log('Hello from Child');
  }
}
let obj = new Child();
obj.greet();