Arrow function is a new way to declare function without writting function and return keyword. It is more concise way than regular function.
Arrow function is very simple. It can be just one line of code and doesn't need curly braces( { } ).
There are three ways to make function in Javascript.
This is the regular function.
let function sayHello(who) {
return `Hello, ${who}!`;
}
This is the regular function as a function express
let sayHello = function(who){
return `Hello, ${who}!`;
}
Here's an arrow function which is same with functions above.
let sayHello = (who) => (`Hello, ${who}!`);
// or
let sayHello = who => `Hello, ${who}!`;
// or
let sayHello = (who) => {return `Hello, ${who}!`};
You can see the arrow function is the shortest and simplest code.
If you want to use curly braces, then you should write return keyword
However, you can't name arrow function! Arrow function always have to be annonymous.