Functions Flashcards

1
Q

What is the concise syntax for an arrow function with one parameter?

A

You can omit the parentheses.

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

How would you define the square function using a concise arrow function syntax?

A

const square = x => x * x.

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

What happens when you try to declare an arrow function with multiple parameters without parentheses?

A

It throws a syntax error.

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

Provide the correct syntax for declaring an arrow function with multiple parameters.

A

const getArea = (width, length, unit) => { /* code */ }.

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

What is an implicit return in arrow functions?

A

The value is returned automatically without the return keyword.

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

How can you implicitly return a single line of code in an arrow function?

A

Omit the return keyword and curly braces.

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

Write an example of an arrow function that adds two numbers using implicit return.

A

const add = (a, b) => a + b.

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

What is the correct way to write an arrow function with no parameters?

A

const greeting = () => alert(Greetings, ${name}!);

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

True or False: Arrow functions with no parameters require parentheses before the arrow token.

A

True.

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

What is the result of using the following syntax: const greeting = => alert(Greetings, ${name}!);

A

Uncaught SyntaxError: Unexpected token ‘=>’

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

In what scenario can you use parentheses to implicitly return a multiline block of code?

A

When you wrap the lines in parentheses instead of curly braces.

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

List the functions that can be written using implicit return.

A
  • const square = x => x * x;
  • const multiply = (x, y) => x * y;
  • const add = (a, b) => a + b;
  • const subtract = (a, b) => a - b;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What does the following code return: const getArea = (width, length, unit) => { const area = width * length; return ${area} ${unit}; }?

A

It returns the area in the specified unit.

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

Fill in the blank: Arrow functions are less verbose than _______.

A

function declarations.

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