Arrow functions use the same syntax as lambdas do in C# (=>) and serve much the same purpose. They are most often used as a shorthand for declaring functions.
- [Instructor] TypeScript has what acutely calls…arrow functions but which in reality…are a stripped down version of lambda expressions.…They're often used as a short form of functions…or to declare functions as you'll see in this next demo.…Let's create a new file and we'll call that lambda.ts…and what we're going to do is to create a function…in the traditional way and then using lambda expressions.…
So, let's create a function called multiplyit…and we'll say that that's equal to a function…that takes num1 which is a number,…num2 which is a number,…the whole function itself is a number…that should all look quite familiar,…and then inside the body of the function,…we'll just say return num1 * num 2;…a perfectly reasonable but small function.…
We can make this a little tighter and neater…using an arrow function.…What we'll say is var multiplyitLambda =…and now, instead of saying function…and passing in the variables,…we just pass in the variables,…num1, which is of type number,…num2, which is of type number,…and then we use the arrow which is an equal sign…
Released
1/5/2017In 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
Share this video
Embed this video
Video: Arrow functions