Skip to main content
D
JavaScript
JavaScript Callbacks

JavaScript Callbacks

JavaScript callbacks pass functions into other functions as arguments.

Read Time
5 min read
Difficulty
Beginner
Last Updated
Jun 15, 2026
Version
v1.0.0

Introduction

JavaScript functions act like regular data, meaning you can pass one function into another. The receiving function will run the callback function later. Developers use this for actions that take time, like waiting for a file to load.

Example

Example
1/* this uses a callback */
2function sayHello() {
3  console.log("Hello!");
4}
5
6setTimeout(sayHello, 3000); // Runs after 3 seconds

Key Points

  • A callback is a function passed as an argument.
  • Callbacks control the execution order of asynchronous code.
  • Using too many nested callbacks creates "callback hell".
  • Modern JavaScript prefers Promises over callbacks.

Up Next

Continue your journey with the next topic.

Go to JS Promises