A class mainly have properties and methods.
Properties are like 'Variables attached to classes'.
Methods are like 'functions attached to classes'.
Let's take a look at a class which has the new gen syntax,
class Human {
gender = 'male';
printGender = () => {
console.log(this.gender);
}
}
class Person extends Human {
name = "Max";
printMyName = () => {
console.log(this.name);
}
}
Here we exclude the constructor function and directly assign the value to a variable inside the class.
And then we use arrow functions syntax to create method inside the class.
Top comments (0)