View

Optional parameter in Javascript function and default value

  1. var myfunc = function(optional) {
  2.   if (typeof optional == “undefined”) {
  3.     optional = “default value”;
  4.   }
  5.   alert(optional);
  6. }

You may also like