1

I read nodejs 5.4 docs, where I found a => symbol in an example and a new way to define callback function. I don't know why => is used ? is it really a new way to define callbacks ? This is the example from node 5.4 docs.

const spawn = require('child_process').spawn;

const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) => {
    console.log(`stdout: ${data}`);
});

ls.stderr.on('data',(data) => {
    console.log(`stdout: ${data}`);
}); 

ls.on('close',(code) => {
    console.log(`child process exited with code ${code}`);
});
Paul
  • 139,544
  • 27
  • 275
  • 264
xenonMohit
  • 21
  • 3
  • I'm sure this is a duplicate, but I wasn't able to find one that just asks what the `=>` symbol is. There are lots of questions about how they work, and explaining the differences between them and normal functions (specifically how `this` works). – Paul Jan 12 '16 at 16:12

1 Answers1

1

It is an EcmaScript 6 arrow function.

It isn't just node.js specific. It works in modern web browsers too.

Paul
  • 139,544
  • 27
  • 275
  • 264