functions with optional args? - Programmers Heaven

Howdy, Stranger!

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

Categories

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.