Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1032067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:01:39+00:00 2026-05-16T14:01:39+00:00

Is just a function that executes after one other function that calls it, finishes?

  • 0

Is just a function that executes after one other function that calls it, finishes?

Please I know (almost) nothing about programming, and I find it quite hard to find a proper newbie answer or explanation about what does this means.

Can I request a try from stackoverflow gurus?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T14:01:40+00:00Added an answer on May 16, 2026 at 2:01 pm

    In general, a callback function is used once another function you have called finishes (just like you stated in your question). A good example of this is AJAX requests: most libraries have a function that allows you to send a request to the server in the background without refreshing the page (this uses AJAX). You generally provide two callback functions to this AJAX function: a success function, and a failure function.

    If this request succeeds, it calls the success function so that your code can do what it needs; for instance, it might refresh part of the page, do some sort of animation, or alert the user that their information was saved. On the other hand, if it failed, the callback function would probably alert the user that their data was not saved and that they should try again.

    Callback functions allow library developers to create very generic code that others can use and then customize to their needs.

    Below is some jQuery code to show you the example above (this code won’t work as the URL doesn’t exist):

    jQuery.ajax(
      url: '/mywebsite/somepage.php',
    
      success: function itWorked(returnedData) {
        // This is the success function and will be called only if the ajax call
        // completes succesfully
    
        alert('Yay it worked! ' + returnedData);
      },
    
      error: function itFailed(originalRequest, textStatus, errorThrown) {
        // This is the error function and will only be called if the ajax call
        // has an error
    
        alert('It failed! ' + textStatus + '. ' + errorThrown);
      } 
    );
    

    EDIT: At the beginning, I said, “In general…”. In reality, callbacks are used for much more than just when a function finishes. Like stated in other answers, it can be used anywhere inside of a function: beginning, middle, end. The basic idea is that the developer of the code may not know how YOU are going to use HIS code. So, he makes it very generic and gives you the ability to do whatever you need with the data.

    A good example of this is the jQuery.each method which allows you to pass in a callback that will be executed on each of the elements in the “array” (I say array because it can actually iterate over many things which may or may not be actual arrays).

    <a href='someurl.html' class='special_link'>Some URL</a>
    <a href='anotherurl.html' class='special_link'>Another URL</a>
    <a href='onelasturl.html' class='special_link'>One Last URL</a>
    
    // The following code says: execute the myEachCallbackFunction on every link
    // that has a class of 'special_link'
    $('a.special_link').each(function myEachCallbackFunction(i) {
    
      // The link variable will contain the object that is currently
      // being iterated over. So, the first time through, it will hold
      // the 'someurl.html' link, the second time it will hold the
      // 'anotherurl.html' link, and the last time it will hold the
      // 'onelasturl.html' link
      var link = $(this);
    
      // Change the background color of each link to be red
      link.css('background-color', 'red');
    });
    

    So, we can see from this example that the developers of jQuery implemented the .each method and allow us to do whatever we want to to each link that it is called upon.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I just want a function that can take 2 parameters: the URL to POST
I have written a function that positions a tooltip just above a textbox. The
I need a function that a user can just click a flash app button
So today I just came across the 'live()' function that binds any future and
I have a function that prepends a li tag to a parent div just
I'm using R5RS Scheme and I just want to implement a function that returns
In Winforms you just have the Main function and that's what runs first, but
I added a function in my .vimrc that's just few search and replace commands.
Working in Delphi7 just now, I noticed that not only a VarIsEmpty function exists,
I know one of the goals of pure functional programming is to eliminate mutability,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.