Skip to main content

Command Palette

Search for a command to run...

Getting Started with OOP in JavaScript: A Beginner's Guide

Updated
2 min readView as Markdown
Getting Started with OOP in JavaScript: A Beginner's Guide
P

Frontend Developer | React & JavaScript Lover ⚛️ | Building cool web apps & sharing my learning journey 💻🚀

Learning Object-Oriented Programming (OOP) can feel a little scary at first. But don’t worry — this post is for absolute beginners! I recently learned OOP concepts under the guidance of DevSync, and here’s a simplified breakdown of what I understood.


🔹 What is OOP?

Object-Oriented Programming (OOP) is a way of writing code using objects. It helps in organizing code in a neat, reusable way.

🔹 The 4 Pillars of OOP

PillarMeaning
EncapsulationWrapping data and methods into one single unit (object)
AbstractionHiding the complex logic and showing only necessary information
InheritanceA class can take properties and methods from another class
PolymorphismA function or method can behave differently based on context/input

🔹 Key Concepts with Examples

🔸 What is a Class?

Think of a class as a recipe or template to create similar types of objects.

Just like you don’t eat the recipe itself, you don’t use a class directly — you use it to create something real: an object.

✅ Without Class:

const car1 = {
  brand: "Toyota",
  start: function () {
    console.log("Car started");
  }
};

const car2 = {
  brand: "Honda",
  start: function () {
    console.log("Car started");
  }
};

✅ With Class:

class Car {
  constructor(brand) {
    this.brand = brand;
  }

  start() {
    console.log(`${this.brand} car started`);
  }
}

const car1 = new Car("Toyota");
const car2 = new Car("Honda");

car1.start(); // Toyota car started
car2.start(); // Honda car started

🔸 What is an Object?

An object is a real thing you make using a class.

Think of a class as the mobile phone blueprint.

An object is the real phone built using that blueprint (like iPhone, Samsung).

class Car {
  constructor(brand) {
    this.brand = brand;
  }

  start() {
    console.log(`${this.brand} is starting`);
  }
}

const car1 = new Car("Toyota");
const car2 = new Car("Honda");

car1.start(); // Toyota is starting
car2.start(); // Honda is starting

💡 Final Thoughts

Learning OOP helped me write clean, reusable code. I now better understand how real applications are structured.

Thanks to DevSync for making OOP so easy to learn for beginners like me!

👉 Learn more at DevSync Official Website

✅written by Pranay Manusmare