0

I was reading some Nodejs JavaScript examples and found something I have never seen before. What is ()=>{} syntax? I tried googling it but not sure what keyword to put in.

  rl.on('line', (input) => {
    console.log(`Received: ${input}`);
  });
bluejimmy
  • 368
  • 6
  • 13
  • Generally referred to as an arrow function: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions – peinearydevelopment Sep 08 '16 at 02:40
  • google es6 arrow function .. – passion Sep 08 '16 at 02:40
  • I'll be like https://babeljs.io/repl/#?babili=false&evaluate=true&lineWrap=false&presets=es2015%2Creact%2Cstage-2&code=rl.on('line'%2C%20(input)%20%3D%3E%20%7B%0A%20%20%20%20console.log(%60Received%3A%20%24%7Binput%7D%60)%3B%0A%20%20%7D)%3B in es5 – link2pk Sep 08 '16 at 02:45
  • If you're planning to be a JavaScript programmer, you should quickly study up on what "ES6" features are. There are any number of good resources on the web about this; try googling "es6 new features". –  Sep 08 '16 at 03:32

1 Answers1

2

It's arrow function which comes in ES6 to define function in new way.

Check the reference here

Example:

let square = x => x * x;
let add = (a, b) => a + b;
let pi = () => 3.1415;

console.log(square(5));
console.log(add(3, 4));
console.log(pi());
abdulbarik
  • 5,407
  • 3
  • 31
  • 54