How to check if a value has been assigned to a variable?
I start with
var val = '';
//then later I assign a value to val
. So before val
is used anywhere I need to be sure if there is a value assigned to val
. How do I do this?
if (typeof name !== "undefined"){
//a value is defined
}
or
if (name != null){
//a value is defined
}