Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

functions with optional args?

tamzynbtamzynb Posts: 2Member
hi,

does anyone know who to implement a optional argument in javascript. If it's possible that is...

i.e

function cloths(socks,shoes,optional pants){
puton=true
...
}

From all searching all I can't find a yes or no, though when I try it like above I get an error.

cheers Tamzyn

Comments

  • DariusDarius Posts: 1,666Member
    : hi,
    :
    : does anyone know who to implement a optional argument in javascript. If it's possible that is...
    :
    : i.e
    :
    : function cloths(socks,shoes,optional pants){
    : puton=true
    : ...
    : }
    :
    : From all searching all I can't find a yes or no, though when I try it like above I get an error.
    :
    : cheers Tamzyn
    :
    In JavaScript all parameters are optional, there is no special syntax for it. I don't think there is a syntax for specifying default parameters.

    Here's an example...

    function test(x){
    alert(x);
    }

    test(5);
    test();

    Why did you think putting optional in would work? or what language did you come from to get that?


    "No Bad Religion song can make your life complete."
    -No Direction, Bad Religion


Sign In or Register to comment.