Test
The code...
/* take one parameter as a string or as an array of strings */
function multipleParameters(param) {
// typetest
if ( typeof param == 'string' ) {
document.write('multipleParameters has param: '+param+'<br>');
// test for property and a function that an array has
} else if ( param.length && param.push ) {
for (var n=0; n<param.length; n++) {
document.write('multipleParameters has param (array): '+param[n]+'<br>');
}
}
}
/* test with one string */
multipleParameters('only one string');
/* test with an array */
multipleParameters( new Array('string1', 'string two', 'another string') );
// ###############################################################################
function multipleArguments() {
if ( arguments && arguments.length > 0 ){
for (var n=0; n<arguments.length; n++) {
document.write('multipleArguments has param (arguments): '+arguments[n]+'<br>');
}
} else {
document.write('multipleArguments has no arguments<br>');
}
}
document.write('<br>');
/* test with no arguments */
multipleArguments();
/* test with one argument */
multipleArguments( 'first argument to function' );
/* test with five arguments */
multipleArguments( 'a string', 5, 'another', 'hey', 'world' );