ES6 Arrow Functions Flashcards
1
Q
What is the syntax for defining an arrow function?
A
(parameters separated by commas) => { code block };
If there is only 1 parameter, the parentheses are not needed. If return is a simple expression, brackets and return keyword can be omitted. Brackets and return keyword are needed for code block if it’s multiline statements.
2
Q
When an arrow function’s body is left without curly braces, what changes in its functionality?
A
Body becomes a return.
3
Q
How is the value of this
determined within an arrow function?
A
Arrow functions: value of this
is determined at definition time
Regular functions: value of this
is determined at call time