Declaring Properties Inside Classes in OOP in JavaScript
At the beginning of a class, you can declare what properties this class will have. For example, let's declare that the user will have the property name:
class User {
name;
show() {
return this.name;
}
}
You can immediately write some value into it:
class User {
name = 'john';
show() {
return this.name;
}
}
Let's now create an object of our class:
let user = new User;
Now let's output the initially specified value:
console.log(user.name); // 'john'
Declare properties name and surn in the Student class.
When declaring, add some values to your properties.