TypeScript Lambda Arrow Function

TypeScript - Lambda / Arrow Functions

Lambda Function/Arrow Function -

The arrow function is additional feature in typescript and it is also known as a lambda function.

Stayed Informed – Learn Angular 2 with TypeScript

A lambda function is a function without a name.

var addNum = (n1: number, n2: number) => n1 + n2;

In the above, the “=>” is a lambda operator and (n1 + n2) is the body of the function and (n1: number, n2: number) are inline parameters.

For example –

let addNum = (n1: number, n2: number): number => { return n1 + n2; }
let multiNum = (n1: number, n2: number): number => { return n1 * n2; }
let dividNum = (n1: number, n2: number): number => { return n1 / n2; }

addNum(10, 2);// Result - 12
multiNum(10, 2);// Result - 20
multiNum(10, 2);// Result - 5

I hope you are enjoying with this post! Please share with you friends. Thank you!!

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.