--- id: 587d7b87367417b2b2512b43 title: Use Arrow Functions to Write Concise Anonymous Functions challengeType: 1 --- ## Description
In JavaScript, we often don't need to name our functions, especially when passing a function as an argument to another function. Instead, we create inline functions. We don't need to name these functions because we do not reuse them anywhere else. To achieve this, we often use the following syntax:
const myFunc = function() {
  const myVar = "value";
  return myVar;
}
ES6 provides us with the syntactic sugar to not have to write anonymous functions this way. Instead, you can use arrow function syntax:
const myFunc = () => {
  const myVar = "value";
  return myVar;
}
When there is no function body, and only a return value, arrow function syntax allows you to omit the keyword return as well as the brackets surrounding the code. This helps simplify smaller functions into one-line statements:
const myFunc = () => "value"
This code will still return value by default.
## Instructions
Rewrite the function assigned to the variable magic which returns a new Date() to use arrow function syntax. Also make sure nothing is defined using the keyword var.
## Tests
```yml tests: - text: User did replace var keyword. testString: getUserInput => assert(!getUserInput('index').match(/var/g), 'User did replace var keyword.'); - text: magic should be a constant variable (by using const). testString: getUserInput => assert(getUserInput('index').match(/const\s+magic/g), 'magic should be a constant variable (by using const).'); - text: magic is a function. testString: assert(typeof magic === 'function', 'magic is a function.'); - text: magic() returns correct date. testString: assert(magic().getDate() == new Date().getDate(), 'magic() returns correct date.'); - text: function keyword was not used. testString: getUserInput => assert(!getUserInput('index').match(/function/g), 'function keyword was not used.'); ```
## Challenge Seed
```js var magic = function() { "use strict"; return new Date(); }; ```
## Solution
```js const magic = () => { "use strict"; return new Date(); }; ```