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

  • Home
  • SEARCH
  • 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 6195021
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:23:45+00:00 2026-05-24T03:23:45+00:00

I’ve noticed that sometimes when I’m passing a callback function in jQuery, I can

  • 0

I’ve noticed that sometimes when I’m passing a callback function in jQuery, I can get away with not having the function specify all the parameters.

For example, in the .each() function, it takes a function which has parameters index,Element. However you can use give it fewer parameters than that as evident in the first example in the documentation: $('li').each(function(index){...}.

When is this valid? And why is this syntactically valid?

  • 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-24T03:23:46+00:00Added an answer on May 24, 2026 at 3:23 am

    What jQuery does is examine the type of the parameters you passed and figures out what you meant. That gives you some flexibility in what you include. This only works when the expected parameters are a different type. For example, if you have three possible parameters for a function: a string, a number and a function, then the receiving function can examine the type of each parameter and figure out which is which no matter what order they are passed in or which ones are included.

    In jQuery, there is usually only one parameter that’s a function so, jQuery can pretty much find it no matter where it is in the parameter list.

    If, on the other hand, the function took two strings or two functions as parameters, then those would have to be passed in the right order so the receiving function could know which was which.

    This can work in javascript because:

    1. If a parameter is not passed to a function, javascript just sets the resulting argument to the function to “undefined” allowing the calling function to see that it was missing when called.
    2. Javascript allows one to examine the types of variables so in this case, the calling function can look at the different types of what was passed and modify it’s behavior.

    If you look at the click() function, you see jQuery has three possible ways to use it:

    .click()
    .click( handler(eventObject) )
    .click( [eventData,] handler(eventObject) )
    

    Internally, the click function in jQuery is declared like this:

    function (data, handler)
    

    Then, when that function is called jQuery looks at the parameters data and handler and determines that if both parameters are undefined, then the caller must have done:

    .click();
    

    If only the handler parameter is undefined and the data parameter is defined and is a function type, then the caller must have used the second form of:

    .click(handler)
    

    In this case, jQuery internally does this to put the parameters into the right slots before using them:

    handler = data;
    data = null;
    

    If both parameters are not undefined, then the caller must have used:

    .click(data, handler)
    

    and it can use both parameters as declared.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a jquery bug and I've been looking for hours now, I can't
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
We're building an app, our first using Rails 3, and we're having to build
I have a text area in my form which accepts all possible characters from
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

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.