Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Introducing ES2015 The Cooler Parts of ES2015 Arrow Functions

Brendan Whiting
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Brendan Whiting
Front End Web Development Techdegree Graduate 84,738 Points

Should I always use arrow functions from here on out?

Arrow functions seem awesome and seem to help me solve problems with 'this'. Is it recommended that after moving to ES2015 we always declare functions with the arrow function syntax and never use the function keyword ever? Would there ever be a good situation to use the old syntax?

(In the same way that they're saying to only ever use const and let and never var from here on out, if I'm not mistaken)

A good answer to your question is described here: https://www.youtube.com/watch?v=oTRujqZYhrU&list=PL57atfCFqj2h5fpdZD-doGEIs0NZxeJTX&index=2

They are inter-changeable in many aspects. A key difference is that the arrow function has this thing called lexical scoping, which as the video explains in really layman's term is that the parent scope (aka one level up).

At the time 6:30 the video provides an example of where the arrow function cannot replace the regular function keyword, as well as a cool workaround.

1 Answer

Saif Tase
Saif Tase
24,578 Points

This article gives a couple good examples of when not to use an arrow function.

Wes Bos: When Not to Use an Arrow Function