When (to and not to) use ES6 Arrow functions in JavaScript?

This anonymity creates some issues:

Harder to debug

No self-referencing

Main benefit: No binding of ‘this’

When you should not use Arrow Functions

Object methods

var cat = {
lives: 9,
jumps: () => {
this.lives--;
}
}

Callback functions with dynamic context

var button = document.getElementById('press');
button.addEventListener('click', () => {
this.classList.toggle('on');
});

When it makes your code less readable

When you should use them

--

--

--

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

Sentry monitoring in your production Electron App

Huawei Maps Kit (React Native)

Create a WhatsApp Clone with Next.js: Chat Page

Collaborne Weekly

Summarize Javascript

How Doctrine has massively improved its Node.js error analysis with Async Hooks

Re-Angular : Angular to React Migration

How to add a WidgetBot Discord chatbot to the NuxtJS website

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

React Router V6. What’s New?

Closures in JavaScript

Hoisting in javascript | Codementor

Fetch JavaScript