Javascript - Callbacks (Intro)
📖 Read the lesson
Code Life
By Pierre Marsaa
What Is a Callback?
In the previous chapter, you passed a function to another function. This has a name: the function you pass is a
callback
.
Here's a classic example:
repeat
takes a number and an action, and runs that action as many times as asked.
↗️
Loading editor...
↶
▶️ Run
↷
repeat
doesn't know what
action
does. It only knows
when
to call it. That separation is the whole point: the same
repeat
works with any action.
Verify