pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: https://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Errors/Unexpected_type

c="/static/client/1111.53dba753dc3eb961.js" type="module">

Esta página ha sido traducida del inglés por la comunidad. Aprende más y únete a la comunidad de MDN Web Docs.

View in English Always switch to English

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

js
// 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

js
if (typeof foo !== "undefined") {
  // Ahora sabemos que foo está definido, ahora podemos continuar.
}

Ver también

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy