Arrow function "expression expected" syntax error

Milkncookiez picture Milkncookiez · Feb 22, 2016 · Viewed 55.5k times · Source

I want to transform this code:

var formatQuoteAmount = function (tx) {
    return Currency.toSmallestSubunit(tx.usd, 'USD');
};
var quoteAmounts = res.transactions.map(formatQuoteAmount);

into an anonymous arrow function. I've written this:

var quoteAmounts = res.transactions.map(tx => Currency.toSmallestSubunit(tx.usd, 'USD'));

I get expression expected syntax error at the arrow. I looked up the default syntax here and seems like the syntax of my code is correct. Any ideas what the problem might be?

I have it working with this syntax:

    var quoteAmounts = res.transactions.map(function (tx) {
        return Currency.toSmallestSubunit(tx.usd, 'USD')
    });

but I want to make it a one-liner, with an arrow-function.

Running on node v5.3.0

Answer

Joe23 picture Joe23 · Feb 26, 2016

I had the error expression expected reported by Webstorm when editing a Node.js program. In this case the solution is to set the language version to a version that supports this feature.

enter image description here