Do I need to pass empty parameters to a javascript function?

frequent picture frequent · Sep 23, 2012 · Viewed 61.8k times · Source

Say I have a function like this, which i'm calling throughout a script:

  function form_senden( form_name, cnf, confirm_txt, trigger_field, ,do_check, chknfcs, allow, errorMsg ){
  // do something 
  }

On most of my function calls, I'm only passing the first parameter.

Question:
Is it ok in this case to omit passing empty parameters like so:

  form_senden("abc");

Or do I need to pass all parameters regardless if they are used like so:

  form_senden("abc","","","","","","","","");

Thanks!

Answer

Gung Foo picture Gung Foo · Sep 23, 2012

It is okay to only pass the first parameter as all other will not be set. If you want to set the 1st and 3rd argument, you will need to make the 2nd null, like so:

form_senden("a",null,"b");