🧭Callback Function
Also known as Callback, Callbacks
A function you give to other code. That code runs it later.
Think of it like
Think of it like leaving your phone number at a shop. They call you when your order is in.
Example
Emma gives setTimeout a callback and a wait of 2 seconds. Then her function runs and shows a message.
Why it matters
Callbacks are used for clicks, timers and file reads. List tools like map take one too.
Definition
Example code
javascript
setTimeout(() => console.log("Done!"), 2000);Common mistake
Key takeaways
- 1Hand it over. Other code holds it.
- 2Run later. When the moment comes.
- 3Nesting hurts. Deep stacks get messy.