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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T20:11:02+00:00 2026-05-26T20:11:02+00:00

I have a function with 2 parameters, it should work whether a the 2nd

  • 0

I have a function with 2 parameters, it should work whether a the 2nd parameter is assigned or not in the bracket. Basically, if it’s assigned then do something if not do something else or just don’t bother about it.

vf.showHide = function (trigger, target) {
    var $trigger = $(trigger),
        trigParent = $trigger.parent(),
        trigDataView = $trigger.data('view'),
        numShown = $trigger.data('showalways'),
        basketSubtotalElem = $('.subtotal .monthlyCost span.price, .subtotal .oneOffCost span.price, .subtotal label h3, .vat *');

    target = target || null; // This is the 2nd parameter but I don't know if this right...

    trigParent.delegate(trigger, 'click', function (e) {
        var elem = $(this);

        target = $(elem.attr('href'));

        e.preventDefault();

        if (trigDataView === 'showhide') {
            if($('.filterBlock')){
                if (target.is(':visible')) {
                    target.hide();
                    elem.find('span').removeClass('minus').addClass('plus');
                } else {
                    target.show();
                    elem.find('span').removeClass('plus').addClass('minus');
                }
            } 
        }
    });
}

So if the function is called like this: vf.showHide('a', 'div') it works and if it’s called with 1 parameter like this: vf.showHide('a') it’s should still works and error is thrown.

Many thanks

  • 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-26T20:11:02+00:00Added an answer on May 26, 2026 at 8:11 pm

    When you invoke a function, if you pass fewer parameters than expected, the parameters you omit are given the undefined value. So in your case:

    vf.showHide = function(trigger, target) {
        if (target === undefined) {
            //target parameter is not passed any value or passed undefined value
            //add code to process here, e.g. assign target a default value
        }
    }
    

    target = target || null: if target is evaluated to false, it’s assigned to null. Take notice that empty string, zero number (0), NaN, undefined, null, false are evaluated to false. So please be careful to write code like that.

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

Sidebar

Related Questions

I have question regarding the use of function parameters. In the past I have
I have a function that accepts wildcard keyword parameters: def func(**kargs): doA doB How
I have a function that uses out parameters to return multiple values to the
I have a function that takes 2 parameters : 1 = XML file, 2
I have a function which takes in two parameters, and returns one or the
I have a function that accepts a char* as one of its parameters. I
I have a function called Colorbox (jQuery plugin) that takes a number of parameters
I have a function that accepts a variable number of parameters: foo (Class... types);
I would like to have a function that modifies some variable list of parameters
I have a calc function in java script that takes three integer parameters, following

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.