When should I use arrow functions in ECMAScript 6?

A while ago our team migrated all its code (a mid-sized AngularJS app) to JavaScript compiled using Traceur Babel. I’m now using the following rule of thumb for functions in ES6 and beyond: Use function in the global scope and for Object.prototype properties. Use class for object constructors. Use => everywhere else. Why use arrow … Read more

When should I use a return statement in ES6 arrow functions

Jackson has partially answered this in a similar question: Implicit return, but only if there is no block. This will result in errors when a one-liner expands to multiple lines and the programmer forgets to add a return. Implicit return is syntactically ambiguous. (name) => {id: name}returns the object {id: name}… right? Wrong. It returns … Read more

What’s the meaning of “=>” (an arrow formed from equals & greater than) in JavaScript?

What It Is This is an arrow function. Arrow functions are a short syntax, introduced by ECMAscript 6, that can be used similarly to the way you would use function expressions. In other words, you can often use them in place of expressions like function (foo) {…}. But they have some important differences. For example, … Read more

Are ‘Arrow Functions’ and ‘Functions’ equivalent / interchangeable?

tl;dr: No! Arrow functions and function declarations / expressions are not equivalent and cannot be replaced blindly. If the function you want to replace does not use this, arguments and is not called with new, then yes. As so often: it depends. Arrow functions have different behavior than function declarations / expressions, so let’s have … Read more