Skip to content
AgileLogics
4 min read

Arrow Functions

Prerequisites: Functions

An arrow function is a shorter way to write a function, especially for short callbacks — the most common style in modern JavaScript.

const greet = (name) => {
    console.log(`Hello, ${name}!`);
};

// A single expression can skip the braces and "return":
const square = (n) => n * n;

console.log(square(6)); // 36

Arrow functions are especially common as arguments to array methods: numbers.map((n) => n * 2).

Common mistakes

  • Adding both { } and expecting an implicit return — with braces, you must write return explicitly: (n) => { return n * n; }.