2018-10-12 15:37:13 -04:00
|
|
|
---
|
|
|
|
title: Use Arrow Functions to Write Concise Anonymous Functions
|
|
|
|
---
|
2019-07-24 00:59:27 -07:00
|
|
|
# Use Arrow Functions to Write Concise Anonymous Functions
|
2018-10-12 15:37:13 -04:00
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Problem Explanation
|
2018-10-12 15:37:13 -04:00
|
|
|
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.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
|
|
|
|
---
|
|
|
|
## Hints
|
|
|
|
|
|
|
|
### Hint 1
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
Get rid of the `function` key word, and plug in this `=>` arrow.
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
### Hint 2
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
Did you get rid of the `var` keyword?
|
|
|
|
|
|
|
|
|
2019-07-24 00:59:27 -07:00
|
|
|
---
|
|
|
|
## Solutions
|
|
|
|
|
|
|
|
<details><summary>Solution 1 (Click to Show/Hide)</summary>
|
2018-10-12 15:37:13 -04:00
|
|
|
|
|
|
|
```javascript
|
|
|
|
const magic = () => {
|
|
|
|
"use strict";
|
|
|
|
return new Date();
|
|
|
|
};
|
|
|
|
```
|
|
|
|
|
|
|
|
As long as you got rid of the `var` keyword, you're good.
|
2019-07-24 00:59:27 -07:00
|
|
|
</details>
|