JavaScript
Objects & classes
A practical reference with examples you can run.
Introduction
Objects group data with related behavior. A class describes how to create those objects. Model a small concept first, such as a learner with a name and a greeting, and keep responsibilities clear.
Syntax & example
class Learner {
constructor(name) { this.name = name; }
greet() { return "Hello, " + this.name; }
}
console.log(new Learner("Alex").greet());Expected output
Hello, Alex
Common mistakes
- Using a variable before assigning a value to it.
- Mixing text and numbers without converting deliberately.
- Skipping an empty input or a boundary value when testing.
Practice
Create a second learner with a different name.
main.jsYour ideas, in code.
Loading your editor…
Run your code to see the output here.
Ready to buildUTF-85 lines