Open In App

How to Declare & use Arrow Functions in TypeScript ?

The arrow function is a concise way of declaring the functions in TypeScript with a lexical binding of this object. The arrow function provides us with a shorter way of declaring functions without using the function keyword just with the help of arrows(=>) and the round brackets(). They can be assigned to a variable created using the let, var, and const keywords in TypeScript. These types of functions have a variable scope and are assigned an undefined value in the memory until a value is assigned to them.

Syntax:

const funcName = () => {
// Function statements and body
}

Example: The below code will explain how you can declare an arrow function in TypeScript.




const add = (a: number, b: number):
    number => {
    return a + b;
}
 
console.log(add(3, 9));

Output:

12
Article Tags :