Classes are more effective than the older way of creating or inheriting objects!
Classes are a template for creating objects. They encapsulate data with code to work on that data. Classes in JS are built on theΒ prototype but also have some syntax and semantics that are unique to classes.
Ways to create a class :
Declaration β
class Students {
constructor(name, age){ //We can use a constructor for inheriting the objects or class
this.name = `You're name is ${name}`;
this.age = `You're age is ${age}`;
}
}
JavaScript
Expression β
const StudentData = new Students(meer, 19);
JavaScript
Usage β
console.log(StudentData.name, StudentData.age);
//Output -> meer, 19
JavaScript
Other Features of Classes :
