You’ve probably seen arrow functions written a few different ways.

//example 1
const addTwo = (num) => {return num + 2;};

//example 2
const addTwo = (num) => num + 2;

//example 3
const addTwo = num => num + 2;

//example 4
const addTwo = a => {
 const newValue = a + 2;
 return newValue;

Some have parentheses around the parameters, while others don’t. Some use curly brackets and the returnkeyword, others don’t. One even spans multiple lines, while the others consist of a single line.

Interestingly, when we invoke the above arrow functions with the same argument, we get the same result.

//Result: 4

How do you know which arrow function syntax to use? That’s what this article will uncover: how to declare an arrow function.

#javascript #es6

How to Declare a JavaScript Function with the New ES6 Syntax
3.10 GEEK