Search code examples
javascriptfunctionparametersoptional-parameters

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


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!


Solution

  • form_senden("abc"); is ok

    the other parameters will be initialized as undefined