How to define an Arrow Function in JavaScript?

JavascriptWeb DevelopmentFront End Technology

An arror function 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 = {
   return num * num;

Define Fat Arrow function in JavaScript

var rank = [7,8,9];
var display = => num*num);

Arrow function definitely reduces the code lines.

Published on 23-Feb-2018 10:48:22