Reputation: 10089
I'd like to create a function wich have a var in argument, if the var is defined return the var value else return the var name
I try
test = function(variable){
try{
if ( typeof(variable) != "undefined" ) {
return 'true'
}
return 'false'
}catch(e){
console.log(e);
}
}
but if I have an undefined var the function isn't called and I have the undefined function error.
I would like to know how to have the variable name too
Thanks :)
Upvotes: 0
Views: 225
Reputation: 16395
don't use var
as your parameter. It it a reserved word in JavaScript and doesn't describe what the variable is used for.
how about:
var test = function(variable) {
if (!variable) return false;
return variable;
}
Upvotes: 1