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 6152389
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:54:42+00:00 2026-05-23T19:54:42+00:00

I am having a tough time conceptualizing what exactly callbacks or hooks are in

  • 0

I am having a tough time conceptualizing what exactly callbacks or hooks are in jQuery. They seem to be lumped together, but I don’t know the difference between them.

From what I understand from other posts about callbacks, like this, a callback is simply a function A that you pass to another function B that calls A once B is done. (That may be totally wrong, correct me if so).

I really don’t have any notion on hooks, other than the statement “you should use a hook/callback.” Something makes me doubt they’re that similar…

  • 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-23T19:54:43+00:00Added an answer on May 23, 2026 at 7:54 pm

    Your definition is close but insufficient. A callback is a function A that you pass to another function B (or to an object B) that B will call at the appropriate point.

    For some functions, “the appropriate point” is after that function completes, as you describe.

    Many functions or objects define a set of “certain points” or events when callbacks can be fired. For example, if you have a control that updates itself periodically via AJAX, it might define an event that occurs when it’s about to update, an event that occurs after the update returns, and an event that occurs after the results have been displayed. For any of these events, you could pass it your custom function that should be called when that event occurs.

    That defined set of points where a custom function might be called is what people mean by “hooks”. They’re places that you can hook your functionality into a prebuilt library.

    Edited to add:

    The OP asked for a simple example of a hook.

    Let’s say I’ve written a function that takes a list of usernames and is designed to go through the list, look up each person’s details, and return a populated list of people objects.

    Maybe I want to give the programmer making use of my function the ability to specify what should happen when a username isn’t found in my database. One programmer might want the function to error out, another might want it to just ignore the missing example, another might want it to look in a different database, another might want it to construct an empty person object.

    So my function signature might be something like

    function getPeople( arrayOfUsernames, missingUsernameCallback )
    

    Within the function, whenever I come to a username that I can’t find in my data, I just call

    missingUsernameCallback( notFoundUsername );
    

    Now the programmer can call the function like

    getPeople( ["adam","betty","charlie"], function(name){ alert("Missing username " + name)} );
    

    and whenever I hit a missing username, I’ll call the function that was passed to me.

    For a more complex case, I might need to accept an object containing multiple callback functions, so it could be called like

       getPeople( ["adam","betty","charlie"], 
            {startOfListCallback:      function(){ alert("I'm starting the list")},
             missingUsernameCallback:  function(){ alert("Missing username"!)},
             endOfListCallback:        function(){ alert("I'm at the end of the list") });
    

    etc. The list of possible callbacks will be defined by the function and should be in the API documentation (along with parameters that could be passed into the callbacks, etc.). That list of callbacks are the hooks.

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

Sidebar

Related Questions

I am having tough time figure out how to change background color of jQuery
I am having a tough time figuring out why this piece of jQuery code
Well, it may actually be a simple case but I'm having a tough time
Excuse my ignorance but I'm having a tough time figuring this out. I'm trying
I'm without my Java reference book and I'm having a tough time finding an
I'm having a tough time formatting this WordPress widget to look good. http://healthybodyguru.com/ It's
I'm having a tough time trying to implement a slideToggle event and at the
I'm having a tough time figuring out a tricky issue. Here is what I
I've been having a tough time entering input with gdb using XCode or Eclipse.
I'm having a tough time find the correct web service or client object model

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.