I’m trying to pass data into my function and if there’s no data being pass it will just use the default value instead.
<a id="process" onclick='process(,"testing","test value")' href="#">Process</a>
function process(passvar1,passvar2,passvar3) {
var defvar1 = 'default value 1',
defvar2 = 'default value 2',
defvar3 = 'default value 3';
if (typeof(passvar1)=="undefined") {
passvar1 = defvar1;
return passvar1;
}
if (typeof(passvar2)=="undefined") {
passvar2 = defvar2;
return passvar2;
}
if (typeof(passvar1)=="undefined") {
passvar1 = defvar1;
return passvar3;
}
alert ('retuern values here ' + passvar1 + ' ' + passvar2 + ' ' + passvar3);
Code play : http://jsbin.com/oledeg/
Looking at your comment, you can simply the function like this:
In your function, since you
returnin each if condition, only first condition is executed and function is returned with just one variable.