Optional Parameters Function - We can specify optional properties on interfaces and the property may be present or missing in the object. Stayed Informed – Learn Angular 2 with TypeScript In the below example, the address property is optional on the following “User” interface. //USER INTERFACE interface User { name: string ; age: number ; address?: string //Optional } //FUNCTION USING USER INTERFACE let userInfo = function (user: User ) { let info = "Hello, " + user.name + " Your Age is - " + user.age + " and Address is -" + user.address; return info; } //USER INFO JSON OBJECT let info = { name : "Anil" , age: 30 }; //RESULT console.log(userInfo(info)); I hope you are enjoying with this post! Please share with you friends. Thank you!!
Angular, React, JavaScript, Java, PHP, SQL, C#, Vue, NodeJs, TypeScript and Interview Questions Answers