1,530 questions
952 votes
11 answers
746k views
Syntax for an async arrow function
I can mark a JavaScript function as "async" (i.e., returning a promise) with the async keyword. Like this: async function foo() { // Do something } What is the equivalent syntax for arrow ...
888 votes
6 answers
166k views
ECMAScript 6 arrow function that returns an object
When returning an object from an arrow function, it seems that it is necessary to use an extra set of {} and a return keyword because of an ambiguity in the grammar. That means I can’t write p => {...
844 votes
3 answers
272k views
Are 'Arrow Functions' and 'Functions' equivalent / interchangeable?
Arrow functions in ES2015 provide a more concise syntax. Can I replace all my function declarations / expressions with arrow functions now? What do I have to look out for? Examples: Constructor ...
748 votes
7 answers
188k views
What do multiple arrow functions mean in JavaScript?
I have been reading a bunch of React code and I see stuff like this that I don't understand: handleChange = field => e => { e.preventDefault(); /// Do something here }
521 votes
14 answers
429k views
What's the meaning of "=>" (a fat arrow formed from equal and greater-than signs) in JavaScript?
I know that the >= operator means more than or equal to, but I've seen => in some source code. What's the meaning of that operator? Here's the code: promiseTargetFile(fpParams, aSkipPrompt, ...
515 votes
9 answers
157k views
When should I use arrow functions in ECMAScript 6?
With () => {} and function () {} we are getting two very similar ways to write functions in ES6. In other languages lambda functions often distinguish themselves by being anonymous, but in ...
388 votes
8 answers
144k views
Can I use ES6's arrow function syntax with generators? (arrow notation)
That is, how do I express function *(next) {} with arrow syntax? I've tried all the combinations I could think of, and I can't find any documentation on it. (I am currently using Node.js v0.11.14.)
263 votes
8 answers
131k views
How do I write a named arrow function in ES2015?
I have a function that I am trying to convert to the new arrow syntax in ES6. It is a named function: function sayHello(name) { console.log(name + ' says hello'); } Is there a way to give it a ...
220 votes
4 answers
158k views
How to use arrow functions (public class fields) as class methods?
I'm new to using ES6 classes with React, previously I've been binding my methods to the current object (show in first example), but does ES6 allow me to permanently bind a class function to a class ...
214 votes
4 answers
124k views
ES6 immediately invoked arrow function
Why does this work in a Node.js console (tested in 4.1.1 and 5.3.0), but doesn't work in the browser (tested in Chrome)? This code block should create and invoke an anonymous function that logs Ok. () ...
210 votes
6 answers
120k views
When should I use a return statement in ES6 arrow functions
The new ES6 arrow functions say return is implicit under some circumstances: The expression is also the implicit return value of that function. In what cases do I need to use return with ES6 arrow ...
183 votes
9 answers
150k views
Why shouldn't JSX props use arrow functions or bind?
I'm running lint with my React app, and I receive this error: error JSX props should not use arrow functions react/jsx-no-bind And this is where I'm running the arrow function (inside ...
182 votes
4 answers
105k views
Using _ (underscore) variable with arrow functions in ES6/Typescript
I came across this construct in an Angular example and I wonder why this is chosen: _ => console.log('Not using any parameters'); I understand that the variable _ means don't care/not used but ...
180 votes
3 answers
127k views
Is it possible to export Arrow functions in ES6/7?
The export statement below gives a syntax error export default const hello = () => console.log("say hello") why ? I'm only able to export named functions export function hello() { console.log(...
172 votes
5 answers
88k views
Using jQuery $(this) with ES6 Arrow Functions (lexical this binding)
Using ES6 arrow functions with lexical this binding is great. However, I ran into an issue a moment ago using it with a typical jQuery click binding: class Game { foo() { self = this; this....