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

Karma-Jasmine

6 JavaScript Features to Improve Your JavaScript Skills in 2022

Learn JavaScript from Scratch in 2022 (5.16)

Create Your Own Google Map Using Mean Stack

Develop A Cross-Platform Mobile App With React Native!

COVID-19, Web Components and clients oh my!

React lazy image loading and TypeScript — No more slow and broken images

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

Function Buzzwords in Javascript

Special Concepts about JavaScript & MongoDB

Javascript, my love/hate story

Using JavaScript and window.postMessage() for Safe Cross-Domain Communication