DEV Community

Shubham_Baghel
Shubham_Baghel

Posted on

4 1

Callback function() in JavaScript

A callback is A reference to executable code, or a piece of executable code, that is passed as an argument to other code or function that is to be executed after another function has finished executing.

In computer programming, a callback, also known as a "call-after" function, is any executable code that is passed as an argument to other code that is expected to call back (execute) the argument at a given time. This execution may be immediate as in a synchronous callback, or it might happen at a later time as in an asynchronous callback. Programming languages support callbacks in different ways, often implementing them with subroutines, lambda expressions, blocks, or function pointers.

Let take an example of Callback function() examples.

function addition(a,b) { console.log("Addition of a+b=", a + b); } function numberAddtion(callback) { a = 10; b=20; callback(a,b); } numberAddtion(addition); //output 30

Heroku

This site is built on Heroku

Join the ranks of developers at Salesforce, Airbase, DEV, and more who deploy their mission critical applications on Heroku. Sign up today and launch your first app!

Get Started

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series 📺

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series 👀

Watch the Youtube series

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay