functionaddNum(x:number,y:number):number{returnx+y;}// void type for no return valuefunctionlog(message:string|number):void{console.log(message);}
interfaces || custom types
interfaceUser{readonlyname:string;// readonly means that the property can only be read, not writtenage:number;experience?:number;//add? for optional property}constuser2:User={name:"Max",age:30,};
classPerson{privateid:number;// private means that the property can only be read, not writtenname:string;constructor(id:number,name:string){this.id=id;this.name=name;}register(){console.log(`${this.id} is registered`);}}constprem=newPerson(1,"Prem Kumar");constprem1=newPerson(2,"kumar kumar");prem.register();
Top comments (0)