What does the "=> " operator mean?

I was seeing some solutions in JavaScript and in one case I saw this command line: return args.reduce((s, v) => s + v, 0);. But I don't know what the => Operator means.

What is its function?

Author: Maniero, 2016-02-21

2 answers

Is known as Arrow functions.
A Arrow function is exactly like a normal function/callback, only less verbose and instance references like this are taken from the "surroundings" (which avoids .bind() or those var that=this).

Then:

var numbers = [1,2,3];
squares = numbers.map(x => x * x);

Which is equivalent to:

squares = numbers.map(function (x) { return x * x });

I don't want to write an extensive answer with all the details because this is redundant. There's so much about it out there that it's not worth the effort. As an example, here there is excellent content on this:

Http://exploringjs.com/es6/ch_arrow-functions.html

 24
Author: felipsmartins, 2020-06-11 14:45:34

This is a function lambda, or as it is often called, arrow function. It is a anonymous function with a simpler syntax. available since EcmaScript 6.

The parentheses on the left are the parameters and what is on the right is the body of the function which is already the expression that generates the result that will be returned in the function.

 9
Author: Maniero, 2019-12-05 17:59:27