Functions: Advanced Flashcards

1
Q

Refactor this to an arrow function (use the return keyword):

const square = function(x) {
        return x * x }
A
const square = (x) => {
        return x * x }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Refactor this to an arrow function without a return keyword (AKA implicit return):

const square = function(x) {
        return x * x }
A

const square = (x) => (
x * x
)

OR

const square = (x) => x * x

You can do this when your arrow function has just one expression to return. If you need to place the expression on its own line, you must wrap the expression in parens.

Otherwise, you can simply write the expression out on the same line without parens.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly