What is a callback function

0 votes
What is a callback function?
Jun 13, 2019 in Others by shubham
• 7,320 points
364 views

1 answer to this question.

0 votes

Callback function is a function which is calling other function  

For example: 

1. console.log('Start')

2. setTimeout(() => {console.log('3 sec Timer'), 3000)}

3. console.log('Stop')

As other programming languages here to the code start with main() function, then when it comes to the first line of the code, it would be executed, so the output would be: Start

Then when it comes to the second line, setTimeout is a callback function as it is a function which has to be executed first, on the completion of it, it would call the second function i.e. console.log('3 sec timer')

but here the o/p 3 sec timer will not come as Node.js does asynchronous programming, the callback function is stored in the place named as callback queue till the main() function gets completed

So it would move to line three now, so the output now would be: 

Start

Stop

Once the main function execution gets completed, the event loop in Node.js would say to execute the callback function which is stored in the callback Queue.

so the final output would be:

Start

Stop

3 Sec Timer

answered Jun 13, 2019 by sunshine
• 1,280 points

Related Questions In Others

0 votes
1 answer

What is a name function in JavaScript & how to define it?

A named function declares a name as ...READ MORE

answered Mar 7, 2019 in Others by Frankie
• 9,830 points
703 views
+1 vote
1 answer

What is Node.js? I want a clear understanding about it.

Node.js is a runtime environment which allows ...READ MORE

answered Jun 17, 2019 in Others by ArchanaNagur
• 2,340 points
262 views
0 votes
1 answer

What is the impact of covid-19 on a global economy?

Covid-19 that is co-corona,vi-virus,d-development,19-In the year 2019.The ...READ MORE

answered Mar 19, 2020 in Others by Niroj
• 82,680 points
512 views
0 votes
1 answer

What is a future data type in Flutter?

Hi@akhtar, Future is a type that ‘comes from the ...READ MORE

answered Aug 11, 2020 in Others by MD
• 95,340 points
332 views
0 votes
1 answer

what is aws lambda function?

AWS Lambda is a serverless computing service ...READ MORE

answered Jan 7 in Others by Edureka
• 5,460 points
23 views
0 votes
1 answer

TypeError: $.ajax(...) is not a function?

Please double-check if you're using the full-version ...READ MORE

answered Feb 22 in Others by Aditya
• 7,280 points
27 views
0 votes
0 answers

Bootstrap modal: is not a function

When I call my model in windows ...READ MORE

May 5 in Others by Kichu
• 16,850 points
19 views
0 votes
1 answer

What is the difference between loadash and underscore

Loadash makes iterating arrays, strings, and objects easy in ...READ MORE

answered Jun 21, 2019 in Others by sunshine
• 1,280 points
310 views
+1 vote
1 answer

what is the difference between error and stderr in Node.js?

Error is an object created by Node.js to handle ...READ MORE

answered Jul 4, 2019 in Others by sunshine
• 1,280 points
1,039 views
webinar REGISTER FOR FREE WEBINAR X
Send OTP
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP