Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
Loading…
Code Lab is in development. New lessons and improvements are on the way. Progress can be deleted.
JAVASCRIPT DATA / CHAPTER 02 / Learn / LESSON 08
Eighth class. A callback is a function passed as an argument to another function. The receiving function decides when to call it.
function applyTwice(fn, value) { return fn(fn(value)); }
const double = (n) => n * 2; console.log(applyTwice(double, 3));
Here double is not called while being passed — the function itself is passed. applyTwice calls it. map, filter, and find use the same idea next.
Common mistake: applyTwice(double(3), 3) passes a number instead of a function; pass double without parentheses.
A callback is a function passed as a value to another function, which calls it.
DATA STANDBY
›