From the course: Typescript for C# Programmers

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Default parameters

Default parameters - Visual Studio Tutorial

From the course: Typescript for C# Programmers

Start my 1-month free trial

Default parameters

- [Narrator] Rather than using optional parameters it's sometimes cleaner to use default parameters, as shown in this next demo. We're going to create a new class called default parameters. Let's call it defaultparams.ts and here we're going to create a new function addit... and that's going to take three numbers as we saw last time, but this time the third value will not be an optional value. It will be a default value. So, let's take a look at what that looks like. Num1 is a number, num2 is a number... this time with num3 we just declare it as a number but then we assign a default value. Let's come down and declare that addit is itself a number. That is the function + return + the number... and then in the body of our function we're going to have a much simpler statement. We can just say let total equal num1... plus num2, plus num3 and this is perfectly safe because if nothing was passed in for num3 it will default to zero and not affect our total at all. Let's go ahead and return…

Contents