Default parameters often make for cleaner code than optional parameters. Default parameters are explained and a demo is used to illustrate their syntax.
- [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 the total…and we're ready to try out our function.…
In this course, Jesse Liberty reviews the fundamentals of TypeScript for the C# developer, including the built-in types, flow controls, and functions. He covers default, optional, and rest parameters; lambda functions; object literals; and the creation and use of custom classes. Plus, learn about other object-oriented features such as inheritance and interfaces. By the end of the course, C# developers should be well on their way to incorporating this flexible and powerful web programming language into their app development workflow.
- Setting up a TypeScript development environment
- Working with types and variables
- Using operators to control flow
- Working with parameters and functions
- Creating classes and objects
- Exploring TypeScript inheritance
- Working with interfaces