JavaScript indefinido
Ejemplos
Variable sin valor:
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";
}
Más ejemplos a continuación.
Definición y uso
La propiedad indefinida indica que a una variable no se le ha asignado un valor o no se ha declarado en absoluto.
Compatibilidad con navegador
undefined()
es una característica de ECMAScript1 (ES1).
ES1 (JavaScript 1997) es totalmente compatible con todos los navegadores:
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | Yes | Yes | Yes | Yes | Yes |
Más ejemplos
Ejemplo
Variable no declarada:
if (typeof y === "undefined") {
txt = "y is undefined";
} else {
txt = "y is defined";
}