How to set a default parameter value in a JavaScript function?

Can someone please explain me how to set a default parameter value for a JavaScript function?

Comments

  • function foo(a, b)
     {
       a = typeof a !== 'undefined' ? a : 1;
       b = typeof b !== 'undefined' ? b : 'defaultval';
       ...
     }
    
  • webdesignkentwebdesignkent United Kingdom

    Yes. You are right david.

Sign In or Register to comment.

Howdy, Stranger!

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

Categories