What are Arrow/lambda functions in TypeScript ? Last Updated : 23 Jan, 2025 Comments Improve Suggest changes Like Article Like Report Arrow functions in TypeScript (also known as lambda functions) are concise and lightweight function expressions using the => syntax.Provide a shorter syntax for defining functions.Automatically bind the context of their surrounding scope.It is commonly used for callbacks, array methods, and simple one-liner functions.Syntax:(param1, param2, ..., paramN) => expression; //Arrow function having multiple parameters() => expressions; //Arrow function with no parameters JavaScript const greet = (name: string): string => `Hello, ${name}!`; console.log(greet("Alice")); Output:Hello, Alice!More Example of Arrow function in TypeScript Arrow Function in a Class JavaScript class Calculator { add = (a: number, b: number): number => a + b; } const calc = new Calculator(); console.log(calc.add(5, 3)); The Calculator class includes an add method defined as an arrow function, which takes two numbers and returns their sum.Using an arrow function ensures that the method inherits the this context from its enclosing class.Output:8Arrow Function with Array Methods TypeScript const numbers = [1, 2, 3, 4, 5]; const squared = numbers.map(n => n * n); console.log(squared); An arrow function is used within the map method to square each number in the numbers array.This concise syntax enhances readability when performing operations on array elements.Output: [1, 4, 9, 16, 25]Arrow Function as a Callback TypeScript setTimeout(() => { console.log("This message is displayed after 1 second."); }, 1000); An arrow function is passed as a callback to setTimeout, which logs a message after a 1-second delay.Arrow functions are ideal for inline callbacks due to their concise syntax and lexical this binding.Output:This message is displayed after 1 second.Best Practices for Using Arrow Functions in TypeScriptUse Arrow Functions for Short Callbacks: Arrow functions are ideal for short and concise callback functions in methods like map, filter, and reduce.Avoid Arrow Functions for Methods in Classes: Use regular functions for class methods that require dynamic this binding, as arrow functions inherit the this context.Return Object Literals Correctly: Wrap object literals in parentheses when returning them in single-line arrow functions to avoid syntax errors.Use Arrow Functions to Maintain this Context: Arrow functions are useful in scenarios where you want to preserve the this context in event handlers or asynchronous code. Comment More infoAdvertise with us Next Article What are Arrow/lambda functions in TypeScript ? isitapol2002 Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League TypeScript Geeks-Premier-League-2022 Similar Reads Arrow functions in JavaScript An arrow function is a shorter syntax for writing functions in JavaScript. Introduced in ES6, arrow functions allow for a more concise and readable code, especially in cases of small functions. Unlike regular functions, arrow functions don't have their own this, but instead, inherit it from the surr 5 min read How to write a function in Typescript ? Writing a function in TypeScript is similar to writing it in JavaScript but with added parameters and return type. Note that any JavaScript function is a perfectly valid TypeScript function. However, we can do better by adding type.Syntax: Let's see a basic TypeScript function syntax (with two argum 4 min read What are Generics in TypeScript ? In this article, we will try to understand all the facts as well as the details associated with Generics in TypeScript along with some coding examples. Generics in TypeScript: Whenever any program or code is written or executed, one major thing one always takes care of which is nothing but making re 3 min read What is the Function type in TypeScript ? TypeScript is a JavaScript-based programming language with a typed syntax. It provides improved tools of any size. It adds extra syntax to JavaScript. This helps in facilitating a stronger interaction between you and your editor. It also helps in catching the mistakes well in advance. It uses type 3 min read What Do Multiple Arrow Functions Mean in JavaScript? In JavaScript, arrow functions provide a concise syntax for writing function expressions. When you use multiple arrow functions in sequence, it typically signifies a series of nested functions, often used for currying or higher-order functions. These are the following methods to show the multiple ar 2 min read TypeScript Assertion functions TypeScript Assertion functions are nothing but the functions that allow us to mainly create the custom type guards that assert the type of a value on our specific criteria. The most suitable use of Assertion Functions is when we are working with the more complex data structures. Syntax:function asse 3 min read Explain the arrow function syntax in TypeScript Arrow functions in TypeScript are implemented similarly to JavaScript (ES6). The main addition in TypeScript is the inclusion of data types or return types in the function syntax, along with the types for the arguments passed into the function.What is arrow function syntax in TypeScript?Arrow functi 3 min read Function Overloading With Generics In TypeScript TypeScript has the ability to overload functions which means multiple signatures may be defined for one single function, this comes in handy when you want a function to behave in a certain way based on the provided parameters. In this article, we will be looking at how function overloading is done u 4 min read Syntax to create function overloading in TypeScript Function overloading is a feature in object-oriented programming where multiple functions can have the same name but different parameters. The parameters can differ in number, types, or both. This allows a single function name to perform different tasks based on the input parameters.Syntax: function 2 min read Like