Let's take an example:
var a; //hereda el valor undefined automaticamente
var b = undefined; //se le asigna el mismo valor pero manualmente
//Si accedemos a los tipos
console.log(typeof a); //"undefined"
console.log(typeof b); //"undefined"
console.log(typeof c); //"undefined"
//Si accedemos a los valores
console.log(a); //undefined
console.log(b); //undefined
console.log(c); //ERROR: c is not defined
if(typeof c !== "undefined"){ //Si introduzco tanto a, como b o como c...
console.log("La variable c SÍ ha sido definida");
} else {
console.log("La variable c NO ha sido definida"); //...el resultado siempre será este.
}
We can see that the operator typeof
gives the same treatment to both an undefined variable (returning "undefined"
) and one that has been defined but with an undefined value (returning "undefined"
as well) independently if it is You have assigned that value manually or not.
My question is: how is it possible to differentiate between those that are defined with an assigned undefined value from those that have not been defined? Plasma in the example: How to get me to detect that c has not been defined unlike a and b, that if they are in spite of having an undefined value?