The syntax for optional parameters is shown and illustrated in a short demo. Optional parameters are essentially the same as in C# and must come after required parameters.
- [Instructor] Functions are a critical aspect…of TypeScript, whether used on their own,…or more commonly, as methods in a class.…As in C#, functions take parameters.…And, as in C#, the final parameter can be optional.…Let's take a look at a quick demo.…To begin, we're going to create another file.…And this time, we'll call that file optionalParams.…Don't forget the extension, .ts, for TypeScript.…
Let's call our function add.…Add is going to take three parameters.…The first, I'll simply call num1,…which will be of type number.…The second, I'll call num2 which is also a number.…The third's a little different.…There's are optional parameter.…So, we say num3?, and that's what indicates…that it's optional.…But, we can still assign it's type, number.…Let's go ahead and give the function itself a type,…which will also be number.…
And then, we can open up the body of the function.…And in the body of the function, let's create…a local variable,…let total = num1 + num2.…Now, you notice that number here has a red squiggly line.…
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