JavaScript Functions 2 Flashcards

(7 cards)

1
Q

What is a Higher-Order function?

A
  1. Functions that accept other functions as an Argument.
  2. Return a functions output.
  3. Or both.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How do functions behave like other data types?

A

Functions can be assigned to variables and then reassigned to a new variable.

const announceThatIAmDoingImportantWork = () => {
console.log(“I’m doing very important work!”);
};

const busy = announceThatIAmDoingImportantWork;

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

What do you not do when assigning an existing function to a new variable OR when passing a callback function as an argument.

A

Do not invoke the function by adding parenthesis ().

Incorrect - const busy = DoingImportantWork();
This assigns the functions return value to the variable.

Correct - const busy = DoingImportantWork;
This assigns the existing function to the new variable.

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

What is a first-class object?

A

They have properties and methods. For example a function is a first-class object.

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

How do you find the original name of a function?

A

Use the name property.

const isTwoPlusTwo = checkThatTwoPlusTwo;

isTwoPlusTwo();

console.log(isTwoPlusTwo.name);

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

What is a callback function?

A

A function that gets passed as an argument to a higher-order function.

The callback function is invoked when the higher-order function is called.

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

What is an anonymous function?

A

A function without a name, an anonymous function can be an argument to.

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