{"post":{"slug":"what-is-a-callback-2026","title":"What Is a Callback in 2026: functions passed to functions","excerpt":"A callback is a function you hand to another function so it can be run later, often when some task finishes. Here is what a callback is and how it works in plain language.","category":"code","date":"June 9, 2026","author":"ByteLedger Team","content":"<span class=\"dropcap\">A</span> callback is a function you pass into another function as an argument, so that the receiving function can run it at the right moment instead of you calling it yourself. The name is literal: you give the function and the other code calls you back when it is ready. Callbacks are how programs react to things that happen later, like a button click, a timer firing, or a file finishing downloading. They are one of the most fundamental patterns in event-driven and asynchronous code, and once the idea clicks, a lot of modern programming stops looking like magic.\n\n## How a callback works\n\nFunctions in languages like JavaScript are values. That means you can store a function in a variable and pass it around just like a number or a string. A callback is simply a function used that way: handed to another function, which decides when to invoke it.\n\n```js\nfunction greet(name) {\n  console.log(\"Hi \" + name);\n}\n\n// pass greet as a callback, do not call it yourself\nsetTimeout(greet, 1000, \"Sam\");\n// greet runs after about one second, called by setTimeout\n```\n\nNotice you wrote `greet`, not `greet()`. You are passing the function itself, not its result. The receiving function, `setTimeout`, holds onto it and calls it later. A function that accepts another function like this is called a higher-order function. If the wider vocabulary is fuzzy, the primer on [what a parameter is](/blog/what-is-a-parameter-2026) helps, since a callback is just a parameter that happens to be a function.\n\n## Synchronous vs asynchronous callbacks\n\nNot every callback runs later. Some run immediately, in order. Sorting an array, for example, calls your comparison function right away. Others run after a delay or once a task finishes, which is the asynchronous case.\n\n| Type | When it runs | Common example |\n|---|---|---|\n| Synchronous | Immediately, in sequence | Array sort, map, filter callbacks |\n| Asynchronous | Later, after a task completes | Timers, network requests, file reads |\n\nThe asynchronous case is the powerful one. It lets a program start a slow job, like fetching data, and keep doing other work. When the data arrives, the callback runs with the result. That is how a single-threaded language stays responsive.\n\n## Callback hell and what replaced it\n\nThe downside shows up when one async step depends on the next, which depends on the next. You end up nesting callbacks inside callbacks, drifting further right across the screen. Developers call this callback hell, and it is genuinely hard to read and debug.\n\nModern code mostly avoids it with promises and async-await, which let you write asynchronous steps in a flat, top-to-bottom style. They did not delete callbacks; they wrap the same idea in a cleaner shape. Understanding callbacks first makes promises far easier to grasp, so see [what a promise in JavaScript is](/blog/what-is-a-promise-in-javascript-2026) once this lands.\n\n## What to skip\n\n- **Deep nesting.** If callbacks pile up more than two or three levels, switch to promises or async-await.\n- **Calling instead of passing.** Pass `fn`, not `fn()`, unless you specifically want the result.\n- **Forgetting error handling.** Async callbacks fail; always handle the error path, not just success.\n- **Overusing callbacks for simple sync logic.** Plain function calls are clearer when nothing is asynchronous.\n\n## FAQ\n\n**What is a callback in simple terms?**\nA function you give to another function so that other code can run it later, at the moment it is ready.\n\n**Why are callbacks used for asynchronous tasks?**\nThey let a program start a slow job and keep working, then run your code once the job finishes, instead of freezing while it waits.\n\n**Are callbacks outdated?**\nNo. Promises and async-await are built on top of callbacks and are nicer for chained steps, but callbacks are still everywhere and still essential to understand.\n\n**What is callback hell?**\nThe tangled, deeply nested code you get when many async callbacks depend on each other. Promises and async-await are the usual fix.\n\n## Where to go next\n\n[What is a parameter](/blog/what-is-a-parameter-2026), [What is a promise in JavaScript](/blog/what-is-a-promise-in-javascript-2026), and [What is async await](/blog/what-is-async-await-2026).","hue":222,"metaTitle":"What Is a Callback in 2026? Plain-English Guide","metaDescription":"What is a callback in 2026? A clear guide to callback functions, how they run later, why they power async code, and how promises improve on callback hell.","keywords":["what is a callback 2026","callback function explained","callback in javascript","callback for beginners","what does callback mean","synchronous vs async callback","callback hell","higher order function","callback vs promise","event callback"],"tldr":["**A callback is a function passed as an argument** — another function calls it back at the right moment instead of you calling it directly.","**It is how code reacts to events** — clicks, timers, and finished downloads all run callbacks when they happen.","**It enables async work** — callbacks let a program keep going while a slow task finishes, then run when the result is ready.","**Promises and async-await built on it** — they exist to tame deeply nested callbacks, but callbacks are still the underlying idea.","**Skip:** stacking callbacks many levels deep; reach for promises or async-await once nesting gets hard to read."],"readTime":"3 min read","wordCount":683},"related":[{"slug":"what-is-the-event-loop-2026","title":"What is the event loop in 2026? Tracing code step by step","excerpt":"The event loop decides what runs next when your code has a call stack, a microtask queue, and a callback queue all waiting. Here is how to trace it.","category":"code","date":"July 24, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":290},{"slug":"sync-vs-async-2026","title":"Sync vs async in 2026: when to use each and why it matters","excerpt":"Synchronous code is simpler; async code handles concurrency. Choosing wrong either blocks your server or creates callback hell. This is the 2026 guide.","category":"code","date":"April 21, 2026","author":"ByteLedger Team","readTime":"5 min read","hue":314},{"slug":"what-is-a-higher-order-function-2026","title":"What Is a Higher-Order Function? 2026 Guide","excerpt":"A higher-order function takes a function as an argument, returns one, or both. Here is why that one capability underpins map, filter, reduce, and most functional-style code.","category":"code","date":"July 18, 2026","author":"ByteLedger Team","readTime":"4 min read","hue":200}],"sameCategory":[{"slug":"bazel-build-explained-2026","title":"Bazel Explained: What Hermetic Builds Actually Cost","excerpt":"Bazel delivers reproducible, precisely cached builds and demands that you describe everything. Here is what you get, what it costs, and who should say no.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":145},{"slug":"graphql-federation-2026","title":"GraphQL Federation: One Graph, Many Teams","excerpt":"Federation composes independently-owned subgraphs into a single API. Here is what it solves, the operational cost it adds, and when a simpler gateway is enough.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":300},{"slug":"hermetic-builds-explained-2026","title":"Hermetic Builds Explained: Same Inputs, Same Output","excerpt":"A hermetic build depends only on declared inputs. Here is what that property gives you, the common leaks that break it, and how to move toward it incrementally.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":130},{"slug":"monorepo-tooling-compared-2026","title":"Monorepo Tooling Compared: What You Actually Need","excerpt":"Monorepo tools solve task orchestration and caching, not repository layout. Here is what each tier provides and how to tell when you have outgrown the simple option.","category":"code","date":"August 19, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":150}],"newer":{"slug":"what-is-a-bull-market-vs-bear-market-2026","title":"Bull market vs bear market in 2026: the difference explained","excerpt":"A bull market is a sustained rise in prices; a bear market is a sustained fall. Here is how each is defined, what drives them, and how long-term investors are meant to respond to both.","category":"finance","date":"June 9, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":52},"older":{"slug":"what-is-a-cd-2026","title":"What is a CD in 2026: certificate of deposit explained","excerpt":"A CD is a savings product where you lock money away for a set term in exchange for a fixed interest rate. Here is how a certificate of deposit works, its trade-offs, and when it makes sense in 2026.","category":"finance","date":"June 9, 2026","author":"ByteLedger Team","readTime":"3 min read","hue":52}}