Callback functions Flashcards

1
Q
"JavaScript is a first-class object"
what does this mean?
A
functions are a class and can be used like any other object (string, array, number, etc) because they are objects themselves.
They can be stored in variables, passed as arguments to functions, created within functions, and returned from functions
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

definition of a callback function

A

Because functions are first-class objects, we can pass a function as an argument in another function and later execute that passed-in function or even return it to be executed later.

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

why are callback functions also known as callback patterns?

A

because it is an established solution to a common problem that can be used as the parameter

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

which function is the callback function?

A

it is the function that is being executed as a parameter of another function

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

what happens to the internal function that is being passed into another function?

A

we are only passing the definition, we are not passing the executing (). Because the containing function has the callback function as a function definition, it can execute the callback anytime.

if it is an anonymous function without a name, it can still be accessed later in the containing functions code vis the arguments object

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

what does it mean that “Callback functions are closures”

A

the callback is executed at some point inside the containing function’s body just as if the callback were defined in the containing function.

This means that the callback functions has access to the containing functions variables and the variables from the global scope

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

filter

A

some code

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

forEach

A

some code

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

map

A

some code

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

reduce

A

some code

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

What type of parameters can be passed to a callback function?

A

variables of the containing function or global variables

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