ES6 Arrow functions in JavaScript

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 })

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Test Driven Development Will Drive You Back to Basics

A child is driving a miniature toy car.

classnames and css Modules

Adding Webpack and Storybook to my component library

Storybook configuration file

Our Experience with Native: R29′s First iOS App is Here!

Working with numbers

Next.js Firebase v9: Styling the ToDo List

You might not need React — A blog about Rails, JavaScript and Trade-Offs

Integrate bootstrap to react application

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.

More from Medium

Destructuring in JavaScript

JavaScript: Interacting with the DOM, Methods and Properties

JS-10 — JavaScript for Programmers, Chapter8