Menu

Understanding JavaScript Classes Objects and the ‘new’ Keyword: A Beginner’s Guide
🖼️

Understanding JavaScript Classes Objects and the ‘new’ Keyword: A Beginner’s Guide

DEV Community·Nabin Kandel·6 months ago
#gzbN85Sr
Reading 0:00
15s threshold

JavaScript Classes & the new Keyword: A Beginner's Guide to OOP 🎯

If you're just starting with JavaScript and Object-Oriented Programming (OOP), the class and new keywords might seem confusing. Let me break it down in the simplest way possible.

📐 What is a Class?

Think of a class as a blueprint or a recipe . It doesn't contain actual data — it just describes what kind of data an object should have.

class Student { name ; age ; gender ; }

Enter fullscreen mode

Exit fullscreen mode

This Student class is like saying: "Every student should have a name, age, and gender."

But we haven't created any actual students yet—just the plan.

🛠️ Creating Objects from a Class

To create actual students (objects) from our blueprint, we use the new keyword:

const ram = new Student (); ram . name = " Ram " ; ram . age = 10 ; ram . gender = " Male " ;

const sita = new Student (); sita . name = " Sita " ; sita . age = 9 ; sita . gender = " Female " ;

const hari = new Student (); hari . name = " Hari " ; hari .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.