Fat-arrow functions

ES2015 also introduces a new syntax for declaring functions called "fat arrow functions." Let's look at a simple variable function definition:

var greet = function(name) {  console.log("Say hello to ", name);};

We could instead write that function definition with fat arrow syntax as follows:

const greet = (name) => {  console.log("Say hello to ", name);};

Fat-arrow syntax also has a number of extra shortcuts you can use to make the amount of code even smaller! For example, if your function just has a single line or is just a return statement, you can rewrite your function as follows:

const greet = (name) => console.log("Say hello to ", name);

Alternatively, you can wrap your return statement in parentheses as well, like ...

Get Phoenix Web Development now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.