javascript – What does the "=>" operator mean?


I was looking at some JavaScript solutions 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 his role?


This is known as Arrow functions .
An Arrow function is just 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 ).


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

which is equivalent to:

squares = (x) { return x * x });

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

Scroll to Top