A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Errors/Unexpected_type below:

TypeError: "x" is (not) "y" - JavaScript

TypeError: "x" is (not) "y" Mensaje
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 de error

TypeError.

¿Qué salió mal?

Tipo inesperado. Esto ocurre amenudo con valores undefined o null .

Además, ciertos métodos, como Object.create () o Symbol.keyFor(), requieren de un tipo específico, que debe ser proporcionado, ejemplos

Casos inválidos
// 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
Cómo solucionar el problema

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.
}
Ver también

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4