DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for JavaScript Interview Questions

Posted on

JavaScript Interview Questions

What's callback?

  • Passing a function definition to another function as an argument is callback.
  • A callback function is a function passed into another function as an argument, which is then invoked inside the outer function to complete some kind of routine or action. ~MDN
function callbackFirst(arg1,arg2,arg3){
    console.log(arg1(), arg2(), arg3() );

callbackFirst( function callbackSecond(){
            return "Returned second callback";
        } , function callbackThird(){
            return "Returned third callback";
        } , function callbackFourth(){
            return "Returned fourth callback";
        } );
Enter fullscreen mode Exit fullscreen mode

The above function will return "Returned second callback Returned third callback Returned fourth callback" as output.

How to differentiate between synchronous and asynchronous callback?

Only setTimeout, setInterval, requests and events are asynchronous, while the other built-in callbacks are synchronous like

Top comments (3)

mxldevs profile image
MxL Devs

A callback is when you meet someone nice at the party and offer your phone number with the instructions "call me :)" and then hope you get a call later.

Synchronous callback is when you sit there staring at your phone waiting for that call.

Asynchronous callback is when you're busy doing your own thing and forgot you gave that number in the first place.

lassiecoder profile image
lassiecoder Author

Love teh way you explained it 👏🏻😃

mxldevs profile image
MxL Devs

Thanks, I've been trying to improve my #ELI5

Take a look at this:


Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. 🛠