- Home
- /
- Tutorials
- /
- JavaScript Tutorial
- /
- JavaScript Class Constructor
JavaScript Classes
JavaScript Class Constructor
The constructor runs when an instance is created and sets up its properties.
It is a special method with a fixed name.
A class can have only one.
Example
Example
javascript
class Person {
constructor(name, age) {
this.name = name;
this.age = age;
}
}
const ada = new Person("Ada", 36);
console.log(ada.name + " is " + ada.age);