Computer >> Computer tutorials >  >> Programming >> Javascript

What is a fat arrow function in JavaScript?


Fat arrow function as the name suggests helps in decreasing line of code. The syntax => shows fat arrow. This also avoids you to write the keyword “function” repeatedly.

Here’s the syntax:

argument => expression

Use the following for more than one argument:

(argument1 [, argument2]) => expression

Let’s compare a function with and without fat arrow:

Function in JavaScript

var rank = [7,8,9];
var display = rank.map(function(num) {
   return num * num;
});

Fat Arrow function in JavaScript

var rank= [7,8,9];
var display = rank.map((num) => num*num);
document.write(arr)

Arrow function definitely reduces the code lines.