JavaScript non definito
Esempi
Variabile senza valore:
let x;
if (x === "undefined") {
text = "x is undefined";
} else {
text = "x is defined";
}
let x;
if (typeof x === "undefined") {
text = "x is undefined";
} else {
text = "x is defined";
}
Altri esempi di seguito.
Definizione e utilizzo
La proprietà undefined indica che a una variabile non è stato assegnato un valore o non è stata dichiarata affatto.
Supporto browser
undefined()
è una funzione ECMAScript1 (ES1).
ES1 (JavaScript 1997) è completamente supportato in tutti i browser:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Altri esempi
Esempio
Variabile non dichiarata:
if (typeof y === "undefined") {
txt = "y is undefined";
} else {
txt = "y is defined";
}