JavaScriptbeginner

Callback

A function passed as an argument to another function, to be called later when something finishes.

Detailed Explanation

A callback is a Function you pass to another function, with instructions: 'When you are done, call this function.' The receiving function will call it at the right moment—after an operation completes, after a delay, or when data arrives.

Callbacks are how asynchronous code works. You request data from a Server, pass a callback, and your code continues. When the data arrives, the server calls your callback. Without callbacks, programs would freeze waiting for slow operations.

Callbacks are everywhere in JavaScript. They are used for event handlers, timers, and data fetching. While newer syntax like Async/Await is cleaner, understanding callbacks is crucial for reading code and solving timing problems.

In authentication, OAuth Callback is a specific callback URL that receives the response after a user signs in with an external provider. onAuthStateChange is a Supabase callback listener that fires when auth events occur.

Code Example

javascript
Free forever

Start building software you actually own.

Learn the concepts, fix things with confidence, and ship real products with AI beside you. No coding background required, and we're with you from the first idea to launch.

Free to start. No card. Leave whenever you want.