BeginnerCoder

Lesson 5 — Classes

Blueprints for objects

A class is a blueprint for making objects that share the same shape and behaviour. The constructor runs when you write new ClassName(...) and stores data on this (the new object). Functions written inside the class are methods — every object made from it can call them.

class Dog {
  constructor(name) { this.name = name; }
  bark() { return this.name + " says woof"; }
}
console.log(new Dog("Rex").bark()); // Rex says woof

Why it matters: classes appear in many libraries and in browser APIs, and they are a tidy way to keep data and the code that uses it together.

Want it another way?
Task

Add a greet() method so the program prints: Hi, Sam

Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.