Skip to Content
Phoenix Web Development
book

Phoenix Web Development

by Brandon Richey
April 2018
Beginner to intermediate content levelBeginner to intermediate
406 pages
9h 33m
English
Packt Publishing
Content preview from Phoenix Web Development

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 ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Phoenix in Action

Phoenix in Action

Geoffrey Lessel
Real-Time Phoenix

Real-Time Phoenix

Stephen Bussey

Publisher Resources

ISBN: 9781787284197Supplemental Content