Sorry for the simple question. I have this function:
function(var1){
var myString =var1;
// myString is parsed for integers
}
Is it necessary to always call the argument as a string? e.g.
function("23")
Or can I safely mix and match? e.g.
function(23);
function("string with number 23");
Yes, you can pass different data types as Javascript is dynamically typed language.
if you want a different behavior depending on the data type, you may use
instanceof.Like this:
This can also be used to filter/validate the input data.
Update: please note @jakeclarkson’s comment regarding the difference between
instanceofandtypeofoperators.