0

I'm getting started with Node and I see => is used for anonymous functions. I have not found this in JavaScript before. Is it Node.js specific? What's the name of this syntax? I searched but could not find anything.

Here below is an example.

process.on('exit', (code) => {
  // do *NOT* do this
  setTimeout(() => {
    console.log('This will not run');
  }, 0);
  console.log('About to exit with code:', code);
});
ocram
  • 1,384
  • 6
  • 20
  • 36
  • Lambda functions, I guess. It's just a shortcut in this case for `function(code){...}` and respectively for the inner `=>` `function(){...}` – nbro May 24 '16 at 17:40

1 Answers1

0

This is an ES6 arrow function.

https://strongloop.com/strongblog/an-introduction-to-javascript-es6-arrow-functions/

var sum = () => 1 + 2;

// effectively equivalent to:

var sum = function() {
    return 1 + 2;
};
Dan Weber
  • 1,227
  • 1
  • 11
  • 22