I am trying to créate a function who have a variable in atribute, if the var exists return the variable else return the var name
app.locals.test = function(myvar){
if ( typeof(myvar) != "undefined" ) {
return myvar
}
return 'false'
}
I have no problem il the var is defined but fi the var is no defined I have testVar is not defined. And I don't haw to get the var name
Thanks for your help
If I am getting your question correct... you wish to return the name of the variable which in the function is locally known as "myvar". So if the above code works then ...the solution can be :
app.locals.test = function(myvar){
if ( typeof(myvar) != "undefined" ) {
return myvar;
} else {
return 'myvar';
}
}
function testVar(variable) {
if (!variable) return 'UNDEFINED VARIABLE';
return variable;
}
But I can't get the var name with javascript