See the Pen thecodelog.com - ES6 Arrow Functions 1 by Deano (@deangilewicz) on CodePen.
Arrow functions have implicit returns, are more concise than ES5 functions, and don’t rebind the value of ‘this’.
Implicit Returns:
Arrow functions allow you to implicitly return something from the function.
See the Pen thecodelog.com - ES6 Arrow Functions 2 by Deano (@deangilewicz) on CodePen.
When explicitly returning something from a function you must use curly braces and the return keyword.
See the Pen thecodelog.com - ES6 Arrow Functions 3 by Deano (@deangilewicz) on CodePen.
When you need to return an object literal you need to use parenthesis around the implicit return.
See the Pen thecodelog.com - ES6 Arrow Functions 4 by Deano (@deangilewicz) on CodePen.
Concise:
Arrow functions that expect one argument can be written with or without parenthesis.
See the Pen thecodelog.com - ES6 Arrow Functions 5 by Deano (@deangilewicz) on CodePen.
When you need to make use of more than one statement in the function body you use curly braces just like regular ES5 functions.
See the Pen thecodelog.com - ES6 Arrow Functions 6 by Deano (@deangilewicz) on CodePen.
When writing an arrow function that has no arguments you must use an empty set of parenthesis.
See the Pen thecodelog.com - ES6 Arrow Functions 7 by Deano (@deangilewicz) on CodePen.
Does Not Rebind ‘this’:
Arrow functions inherits the context of ‘this’ from its parent scope.
See the Pen thecodelog.com - ES6 Arrow Functions 8 by Deano (@deangilewicz) on CodePen.
When not to use Arrow Functions:
1. When you need ‘this’ (see above).
2. When you need a method to bind to an object.
See the Pen thecodelog.com - ES6 Arrow Functions 9 by Deano (@deangilewicz) on CodePen.
3. When you need to add a prototype method.
See the Pen thecodelog.com - ES6 Arrow Functions 10 by Deano (@deangilewicz) on CodePen.
4. When you need the arguments object.
See the Pen thecodelog.com - ES6 Arrow Functions 11 by Deano (@deangilewicz) on CodePen.