Lesson 18 of 20
Classes
Create objects with shared behavior.
Introduction
A class is a template for objects. The constructor initializes state and methods describe behavior.
Classes use new to create instances and can extend another class when specialization is useful.
Key insight
Create objects with shared behavior.
Example
class User {
constructor(name) { this.name = name; }
greet() { return `Hi, ${this.name}`; }
}
console.log(new User("Asha").greet());This example shows the core classes idea in a small, runnable program.
Real-world example
Classes model SDK clients, game entities and domain objects.
Test yourself
2-question check
1
What is the main idea in Classes?
2
Where can classes be useful?
Ready to check your understanding?
Answer every question, then submit your quiz.
Try it yourself
JavaScript compiler
Runs in your browser. Nothing is sent to a server.
Output appears here
Practice challenge
Create a Product class with a name and price.