Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2005
    Location
    France, Bordeaux
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Function with default paramater values?

    Hi guys,

    Isn't there a way to declare a function with paramters having default values

  • #2
    New Coder
    Join Date
    Aug 2004
    Posts
    68
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hi,

    JS doesnt have default Parameters option....
    This is a work around...

    Code:
    function someFunction(param1, param2,param3){
    if(param1==null) param1="hello ";
    if(param2==null) param2="how ";
    if(param3==null) param3="are you?";
    alert(param1+param2+param3);
    }
    
    someFunction("hi","how","is life");
    someFunction("hi");
    Afru.

  • #3
    New Coder
    Join Date
    Mar 2005
    Location
    France, Bordeaux
    Posts
    44
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Not bad

    In fact this is a workaround, but pretty elegant.
    What about function overloading as in some other modern languages, is it feasable?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •