ES6 Arrow functions in JavaScript

Arrow functions (also called “fat arrow functions”) are undoubtedly one of the more popular features of ES6.

Variations

1. No parameters

() => 42
_ => 42

2. Single parameter

x => 42  || (x) => 42

3. Multiple parameters

(x, y) => x * y

4. Statements (as opposed to expressions)

var feedTheCat = (cat) => {
if (cat === 'hungry') {
return 'Feed the cat';
} else {
return 'Do not feed the cat';
}
}

5. “Block body”

var addValues = (x, y) => {
return x + y
}

6. Object literals

x =>({ y: x })

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Abhay Jain

Abhay Jain

Developer with 3 yrs of industrial experience in developing scalable web applications.