| [ Web Proxy ] |
| Viewing: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Errors/Unexpected_type | [Back] [Original] |
Get to know MDN better
Esta pgina ha sido traducida del ingls por la comunidad. Aprende ms y nete a la comunidad de MDN Web Docs.
TypeError: "x" is (not) "y" Examples: TypeError: "x" is undefined TypeError: "x" is null TypeError: "undefined" is not an object TypeError: "x" is not an object or null TypeError: "x" is not a symbol
Tipo inesperado. Esto ocurre amenudo con valores undefined o null .
Adems, ciertos mtodos, como Object.create() o Symbol.keyFor(), requieren de un tipo especfico, que debe ser proporcionado, ejemplos
// undefined and null cases on which the substring method won't work
var foo = undefined;
foo.substring(1); // TypeError: foo is undefined
var foo = null;
foo.substring(1); // TypeError: foo is null
// Certain methods might require a specific type
var foo = {};
Symbol.keyFor(foo); // TypeError: foo is not a symbol
var foo = "bar";
Object.create(foo); // TypeError: "foo" is not an object or null
Para fijar un puntero nulo a indefinidos o valores nulos, puede utilizar el operador typeof, por ejemplo
if (typeof foo !== "undefined") {
// Ahora sabemos que foo est definido, ahora podemos continuar.
}
This page was last modified on 29 may 2026 by MDN contributors.
Your blueprint for a better internet.
Portions of this content are 19982026 by individual mozilla.org contributors. Content available under a Creative Commons license.
| Web Proxy Viewer | New URL | Original Page |