Foundations Updated 2026-09 View as Markdown

Arrow Functions

Arrow functions are a feature of ES6, their behavior are generally the same of a function.

Arrow functions are a feature of ES6, their behavior are generally the same of a function. These are anonymous functions with a special syntax, they haven’t their own this, arguments or super. They can’t be used as constructors too.

Arrow functions are often used as callbacks of native JS functions like map, filter or sort. The reason of their name is due to the use of => in the syntax.

To define an arrow function, we use the () => {} structure as follows:

typescript
const greet = (name) => { return "Hello " + name + "!"; }

console.log(greet("Eric"));      // prints out Hello Eric!

In this function, the name argument to the greet function is used inside the function to construct a new string and return it using the return statement.

In case that the function only receives one argument, we can omit the parenthesis:

typescript
const greet = name => { return "Hello " + name + "!"; }

console.log(greet("Eric"));      // prints out Hello Eric!

And, in case that we want to do a explicit return of the function and we have only one line of code, we can avoid the return statement and omit brackets too:

typescript
const greet = name => "Hello " + name + "!";

console.log(greet("Eric"));      // prints out Hello Eric!

Using an arrow as a callback compared to a normal function:

typescript
let numbers = [3, 5, 8, 9, 2];

// Old way
function multiplyByTwo(number){
    return number * 2;
}

let multipliedNumbers = numbers.map(multiplyByTwo);

console.log(multipliedNumbers);              // prints out: 6, 10, 16, 18, 4

// Using ES6 arrow functions
const multiplyByTwo = number => number * 2;

let multipliedNumbers = numbers.map(multiplyByTwo);

console.log(multipliedNumbers);              // prints out: 6, 10, 16, 18, 4
Exercise

Try it

run this one locally

Expected output

const greet = name => "Hello " + name + "!";

console.log(greet("Eric"));      // prints out Hello Eric!

Get the TypeScript agent pack

A battle-tested AGENTS.md, the review checklist, and the failure-mode cheat sheet for TypeScript. One email, then occasional updates when the tooling shifts. No course pitch.

Unsubscribe in one click. We never sell the list. Or just take the AGENTS.md now — no email needed.