rpgs_player rpgs_player - 4 months ago 7x
Javascript Question

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, relatedURI).then(aDialogAccepted => {
if (!aDialogAccepted)

saveAsType = fpParams.saveAsType;
file = fpParams.file;

}).then(null, Components.utils.reportError);


What It Is

This is an arrow function. Arrow functions are a new, short syntax 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) {...}.

Arrow functions are part of the ECMAscript 6 specification, but not part of "normal" JavaScript in use in most browsers today. They are, however, partially supported in Node v. 4.0+ and in many browsers (see below).

You can read more in the Mozilla documentation.

From the docs:

An arrow function expression (also known as fat arrow function) has a shorter syntax compared to function expressions and lexically binds the this value (does not bind its own this, arguments, super, or new.target). Arrow functions are always anonymous.

Example Code

Example (also from the docs):

var a = [
  "We're up all night 'til the sun",
  "We're up all night to get some",
  "We're up all night for good fun",
  "We're up all night to get lucky"

// These two assignments are equivalent:

// Old-school:
var a2 = a.map(function(s){ return s.length });

// ECMAscript 6 using arrow functions
var a3 = a.map( s => s.length );

// both a2 and a3 will be equal to [31, 30, 31, 31]

Notes on Compatibility

You can use arrow functions in Node, but browser support is spotty.

Browser support for this functionality has improved quite a bit, but it still is not widespread enough for most browser-based usages. As of April 7, 2016, it is supported in current versions of:

  • Chrome (v. 45+)
  • Firefox (v. 22+)
  • Edge (v. 12+)
  • Opera (v. 32+)
  • Android Browser (v. 47+)
  • Opera Mobile (v. 33+)
  • Chrome for Android (v. 47+)
  • Firefox for Android (v. 44+)

Not supported in:

  • IE (through v. 11)
  • Safari (through v. 9.1, but it is supported in the Technical Preview, so it's coming)
  • iOS Safari (through v. 9.3)
  • Opera Mini (through v. 8.0)
  • Blackberry Browser (through v. 10)
  • IE Mobile (through v. 11)
  • UC Browser for Android (through v. 9.9)

You can find more (and more current) information at CanIUse.com (no affiliation).