Arrow functions, also known as “fat arrow” functions, are a shorter syntax for writing function expressions in JavaScript. They are defined using the “=>” operator and do not have their own “this” binding, instead they inherit the “this” value of the surrounding scope.

Here is an example of an arrow function that takes in a single argument “x” and returns its square:

let square = x => x * x;
console.log(square(5)); // 25

Arrow functions can also have multiple arguments, like so:

let add = (a, b) => a + b;
console.log(add(1, 2)); // 3

Arrow functions are also useful when working with arrays, as they can be used in method calls such as ‘map’, ‘filter’, and ‘reduce’.

let numbers = [1, 2, 3, 4, 5];
let squaredNumbers = => x * x);
console.log(squaredNumbers); // [1, 4, 9, 16, 25]

Also Read:

Categorized in: