freeCodeCamp Challenge Guide: Use Arrow Functions to Write Concise Anonymous Functions

Use Arrow Functions to Write Concise Anonymous Functions


Problem Explanation

Again, ES6 is all about making JavaScript more elegant, and for some, more readable.

Anonymous functions, as stated, can be created when you are sure that the function will not be called by name anywhere else.


Hints

Hint 1

Get rid of the function key word, and plug in this => arrow.

Hint 2

Did you get rid of the var keyword?


Solutions

Solution 1 (Click to Show/Hide)
const magic = () => {
  return new Date();
};

As long as you got rid of the var keyword, you’re good.

Solution 2 (Click to Show/Hide)
const magic = () => new Date();

Single line arrow function with an implicit return.

31 Likes