O'Reilly logo

Learning Angular for .NET Developers by Rajesh Gunasundaram

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Optional and default parameters

Consider that we have a function with three parameters, and sometimes, we may only pass values for the first two parameters in the function. In TypeScript, we can handle such scenarios using the optional parameter. We can define the first two parameters as normal and the third parameter as optional, as given in the following code snippet:

function CutomerName(firstName: string, lastName: string, middleName?: string) {     if (middleName)         return firstName + " " + middleName + " " + lastName;     else         return firstName + " " + lastName; } //ignored optional parameter middleName var customer1 = customerName("Rajesh", "Gunasundaram");  //error, supplied too many parameters  var customer2 = customerName("Scott", "Tiger", ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required