Constructor Without Parameters
You'll learn when and why to create classes with an empty constructor—or skip it entirely.
The Core Idea
Not every class needs initialization parameters. Sometimes a class represents objects that start with the same default values, or it only needs methods and no initial state at all. In these cases, you can write a constructor with no parameters, or even omit the constructor entirely—JavaScript provides a default one automatically.
Empty Constructor vs No Constructor
If your class doesn't need any setup logic, you have two choices:
// Option 1: Explicitly write an empty constructor
class Timer {
constructor() {
// No parameters, no setup needed
}
start() {
console.log("Timer started!");
}
}
// Option 2: Omit the constructor entirely
class Counter {
increment() {
console.log("Count increased");
}
}
Both approaches work identically. JavaScript automatically provides an invisible empty constructor if you don't write one. The new keyword still works:
const myTimer = new Timer();
const myCounter = new Counter();
When to Use This Pattern
Use constructors without parameters when:
- All instances start with identical default values
- Your class only contains methods (utility classes)
- Initialization logic will happen later via method calls
Think of it like a blank notebook—every notebook starts the same way, ready to be used.
Key Takeaway: If your class needs no initialization parameters, you can write an empty constructor() or omit it entirely—JavaScript creates a default constructor automatically, and instances are created normally with new.