All Questions

3425
votes
23answers
902562 views

How do I return the response from an asynchronous call?

I have a function foo which makes an Ajax request. How can I return the response from foo? I tried to return the value from the success callback as well as assigning the response to a local variable ...
106
votes
2answers
16052 views

Arrow function vs function declaration / expressions: Are they equivalent / exchangeable?

Canonical question If you find a question about issues after replacing a function declaration / expression with an arrow function, please close it as duplicate of this one. Arrow functions in ES2...
206
votes
8answers
52078 views

What's the meaning of "=>" (an arrow formed from equals & greater than) 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, re...
2454
votes
21answers
537972 views

What's the difference between using "let" and "var" to declare a variable?

ECMAScript 6 introduced the let statement. I've heard it described as a "local" variable, but I'm still not quite sure how it behaves differently than the var keyword. What are the differences? When ...
125
votes
8answers
41111 views

Unable to access React instance (this) inside event handler

I am writing a simple component in ES6 (with BabelJS), and functions this.setState is not working. Typical errors include something like Cannot read property 'setState' of undefined or th...
82
votes
6answers
23115 views

One-liner to take some properties from object in ES 6

How one can write a function, which takes only few attributes in most-compact way in ES6? I've came up with solution using destructuring + simplified object literal, but I don't like that list of fie...
280
votes
7answers
46087 views

When should I use Arrow functions in ECMAScript 6?

The question is directed at people who have thought about code style in the context of the upcoming ECMAScript 6 (Harmony) and who have already worked with the language. With () => {} and function...
43
votes
4answers
2504 views

Javascript object bracket notation ({ Navigation } =) on left side of assign

I haven't seen this syntax before and am wondering what it's all about. The brackets on the left are throwing a syntax error: "unexpected token {" var { Navigation } = require('react-router'); I'm ...
12
votes
3answers
3157 views

Methods in ES6 objects: using arrow functions

In ES6, both of these are legal: var chopper = { owner: 'Zed', getOwner: function() { return this.owner; } }; and, as shorthand: var chopper = { owner: 'Zed', getOwner() { return t...
131
votes
3answers
20278 views

Are variables declared with let or const not hoisted in ES6?

I have been playing with ES6 for a while and I noticed that while variables declared with var are hoisted as expected... console.log(typeof name); // undefined var name = "John"; ...variables decla...

Previous Next