const myFunc = function() {ES6 provides us with the syntactic sugar to not have to write anonymous functions this way. Instead, you can use arrow function syntax:
const myVar = "value";
return myVar;
}
const myFunc = () => {When there is no function body, and only a return value, arrow function syntax allows you to omit the keyword
const myVar = "value";
return myVar;
}
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.
magic
which returns a new Date()
to use arrow function syntax. Also make sure nothing is defined using the keyword var
.
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.'');'
```