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

Advanced React: How to Build User Idle Component using Hooks

JavaScript Fundamentals: Objects

Functional components are not so good with Firebase Realtime Db/ FireStore

JavaScript Fetch API Example

What is this React Hooks

Testing Vue.js in Rails with Webpacker and Jest

Angular RxJS: Why I was wrong, You should always use subscribes, not promises.

How To Remove Un-used Imports Automatically In Visual Studio Code

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

Special Concepts about JavaScript & MongoDB

Javascript ES6 Modules

JavaScript Proxy

JavaScript objects in depth.