ES6 Arrow Functions Cheatsheet
Published in
3 min readFeb 11, 2019
Here’s a cheatsheet to show you the many ways to write your arrow functions.
// Explicit Return, Multi-Line
a => {
return a
}// Explicit Return, Single-Line
a => { return a }// Implicit Return, Multi-line
a => (
a
)// Implicit Return, Single-Line
a => a// Multiple Parameters, Parentheses Required
(a, b) => a, b
Implicit vs Explicit Return
We have several ways of writing our arrow functions. This is because arrow functions can have either “implied return” or “explicit return” keyword.
With normal functions, if you want to return something, you have to use the return
keyword. Arrow functions also have that. When you use the return
keyword, it's called an explicit return. However, arrow functions up their game and allow something called implied return where the return
keyword can be skipped. Let's look at some examples 🤓:
Example A: Normal Function
const sayHi = function(name) {
return name
}
Example B: Arrow Function with Explicit Return
// Multi-line
const sayHi = (name) => {
return name
}// Single-line
const…