Callback functions Flashcards
"JavaScript is a first-class object" what does this mean?
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
definition of a callback function
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.
why are callback functions also known as callback patterns?
because it is an established solution to a common problem that can be used as the parameter
which function is the callback function?
it is the function that is being executed as a parameter of another function
what happens to the internal function that is being passed into another function?
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
what does it mean that “Callback functions are closures”
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
filter
some code
forEach
some code
map
some code
reduce
some code
What type of parameters can be passed to a callback function?
variables of the containing function or global variables