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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:53:15+00:00 2026-06-10T12:53:15+00:00

I have been using jQuery for a year, but I still don’t understand how

  • 0

I have been using jQuery for a year, but I still don’t understand how this code works:

alert($('#elementID').val()); // It gets the value of element

$('#elementID').val('setting Value'); // the same function is setting value

some other functions of jquery also do the same like .html()

I want to know how this thing is achieved? How do they overload a javascript function?

  • 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-06-10T12:53:16+00:00Added an answer on June 10, 2026 at 12:53 pm

    There are no overloads in javascript, so feats like this are performed using optional parameters. JavaScript allows you to call functions without specifying parameters. For example:

    function val(text)
    {
      if (arguments != null && arguments.length > 0) {
        alert("i'm setting value here to " + text);
      } else {
        alert("i'm getting value here");
      }
    }
    
    val(); // alerts value getter
    val('hi!'); // alerts value setter and the message
    

    This example was written to point out arguments collection which you get in every function. Every function can fetch it’s parameters as a collection and can accordingly perform it’s logic. However, displayed example would be written differently in real world:

    function val(text)
    {
      if (typeof text === "string") {
        alert("i'm setting value here to " + text);
      } else {
        alert("i'm getting value here");
      }
    }
    

    Each parameter which you do not pass to a function gets “value” of undefined (not null). This lets you use the shortest logical expression. You can use any value in if statement. Variables which are null or undefined will simply be evaluated as false.

    As a comment below pointed out if text parameter is empty string if (text) would return false. For that reason, for text parameters check parameters by type.

    It would be beneficial for you to also read about null and undefined differences.

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

Sidebar

Related Questions

I have been using mootools for a year now. I need to use jquery
I have been using a jquery slideshow, but when I include a jquery newsticker
I have been using jQuery for some time and this one's stumping me- I
I have been using jQuery prettyPhoto plugin to show inline html content. This content
I have been using jQuery lately, but never used JSON with it. Now, I
I have been using jquery ui with no problem but just recently the jquery
I have been using the following code for loading JQuery in all of my
I have been using JQuery UI dialog box.The following code I am using.Can any
I have been using jQuery for all my projects in PHP, Java etc. but
I have been using the jquery appear plugin for some time now, but it

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.