Public modifier in TypeScript
Properties and methods declared via the public modifier are available for reading and writing outside the class. Let's see in practice. Let's make our class have a public property name:
class User {
public name: string = '';
}
Let's create an object of the class:
let user = new User();
Let's change the value of the property:
user.name = 'john';
Let's read the property:
console.log(user.name);
Create a class User that will contain public properties with the user's name and year of birth. Create a public method getAge that will get the user's age based on their year of birth.