Arrow functions in Javascript ES6

Posted in Tutorials

Tweet This Share on Facebook Bookmark on Delicious Digg this Submit to Reddit

Continuing from the last tutorial, we changed the anonymous function in an arrow function like this…

arrow function

This is equivalent to use of anonymous function…

arrow function equivalent

but is much more concise.

You drop the function keyword and add the arrow operator.  The input parameters are on the left and function body on the right.  If there are more than one input param, you enclose in parenthesis and separate them by commas.  If there are more than one line in the function body, you need to bound the body in curly braces and are formatted as such …

arrow-function-multi-line

Another thing to note about arrow functions is that the “this” binding has changed from previous.  More about this referenced here.

More ES6 features here.