DRAFT
CallbackParametersInCaller
Misconception:
A function that accepts a callback with some parameters may be written with the parameters of the callback as parameters of the original calling function.
Incorrect
Parameters of a callback function may be written as parameters of the caller function
Correct
A function that expects a callback has that callback function as a parameter
SymptomsHow do you know your students might have this misconception?
How do you know your students might have this misconception?
Many functions in JavaScript are higher-order functions
that accept “callback” functions as arguments.
A classic example can be shown with the forEach
function,
that calls a function on each element of an array.
A student holding this misconception may write code like this:
arr.forEach(element) {
// Do something with element
}