Friday, September 11, 2015

Is there a better way to do optional function parameters in Javascript?

Is there a better way to do optional function parameters in Javascript?

use a default value if the parameter is omitted:

if (typeof optionalArg === 'undefined') {
  optionalArg = 'default';
}

Reference:

http://stackoverflow.com/questions/148901/is-there-a-better-way-to-do-optional-function-parameters-in-javascript

No comments: