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 trialHayden Lau
4,186 PointsWhy function executeCallback(callback) { callback(); }; did not also get converted into arrow function?
Can someone explain to me in the arrow function tutorial,
They only converted the Print Hello and Print Goodbye into arrow function. but not the function declaration of executeCallBack(callback)?
Below is the code:
function executeCallback(callback) { callback(); };
//Print Hello executeCallback(() => console.log('Hello'));
//Print Goodbye
executeCallback(() => console.log('Goodbye'));
Thanks!
Hayden
1 Answer
Steven Parker
231,261 PointsThe other functions are anonymous, and the conversion of anonymous functions seems to be the point of this lesson.
But the named function could also be written in the "arrow" style:
const executeCallback = callback => callback();
But be aware that arrow functions can't always replace conventional ones, particularly as constructors, class methods, generators, and anywhere "this" or "arguments" are used. For more details, see the MDN page on Arrow Functions.
Hayden Lau
4,186 PointsHayden Lau
4,186 PointsGot it. Thanks for the help!