6
Assuming a Javascript function with parameters:
function minhaFuncao (param1, param2, param3) {
// fazer algo ...
}
And then using it as follows:
var param1 = "bubu";
minhaVariavel = minhaFuncao (param1);
or
var param1 = 30,
param2 = true;
minhaFuncao (param1, param2);
Question
How we can verify, within the function, whether a parameter of any type has been provided to avoid using the same ?
Example using the parameter without receiving the same:
function minhaFuncao (param1) {
alert("BuBu diz: " + param1);
}
minhaFuncao();
Note: It does not matter the type of parameters, it matters whether they were received to avoid problems in logic or to act accordingly.
Can they be of these types or should they be of these types respectively? Or they can be any of the three but not if it is of another type, is considered without valid parameter?
– Maniero
@Bigown Edited to best illustrate the intended. The type is indifferent to the problem at hand.
– Zuul
I didn’t think it was so simple, it’s almost dup de http://answall.com/q/56710/101 which is already a dup.
– Maniero
@Bigown The subjects in the two you refer to are different from the one we find ourselves commenting on. Although the answers are quite complete and eventually refer to the solution to the problem we have in hand in this question, the others do not seek to know whether or not the parameter has been provided. In this seeks to set default value, in this also. The point is that looking for this particular problem I did not reach the questions/answers you referred to...
– Zuul
Yes, of course, that’s why I almost said. In this case you do what you want if you do not receive the parameter, in those what to do is already specified.
– Maniero
@bigown That’s it! I just clarified not to induce future readers to close as dup. They are related yes, but are not equal ;)
– Zuul
Who gave downvote, it would be good to know the reason to improve what has to improve or remove the question if it is not good for this site!
– Zuul