What is an Arrow Function in JavaScript?

JavascriptWeb DevelopmentFront End Technology

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.

Syntax

Here’s the syntax −

argument => expression

Use the following for more than one argument −

(argument1 [, argument2]) => expression

Let’s compare a function with and withour 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.

raja
Published on 16-Feb-2018 12:25:34
Advertisements