VOOZH about

URL: https://www.geeksforgeeks.org/typescript/explain-the-arrow-function-syntax-in-typescript/

⇱ Explain the arrow function syntax in TypeScript - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Explain the arrow function syntax in TypeScript

Last Updated : 11 Sep, 2025

Arrow functions in TypeScript are similar to JavaScript (ES6) but allow you to add type annotations for parameters and return values. They provide a concise and type-safe way to define functions.

  • Shorter and clearer syntax compared to traditional functions.
  • Support parameter and return type annotations.
  • Preserve the lexical scope of this, avoiding common context issues.

Syntax

let function_name = (
parameter_1 : data_type,
...
) : return_type => {
...
}

In the above syntax:

  • let:sed to declare the arrow function and assign it to a variable.
  • function_name: The name of the variable holding the arrow function.
  • parameter_1: data_type: Function parameter with its type annotation. Multiple parameters can be separated by commas.
  • ... : Indicates additional parameters may be defined.
  • : return_type: Specifies the type of value the function will return.

Example 1: Returning a String

In this example, we create a function that returns a string. The function takes a name as a parameter and returns it.

Output:

GeeksforGeeks

Example 2: Adding Two Integers

In this example, we create a function to add two integers. The function takes two parameters of type number and returns their sum, also of type number

Output:

140
180
190

Example 3: Using Multiple Data Types

In this example, we create a function that returns a string composed of three different data types. The function takes a number, a string, and an array of numbers as parameters, and returns a formatted string.

Output:

1- ABC - 10,20,30
2- APPLE - 50,20,30
3- MANGO - 70,90,80


Comment

Explore