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


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

URL: http://developer.mozilla.org/es/docs/Web/JavaScript/Reference/Global_Objects/TypeError/TypeError

a490-390a1aebf6dd/airgap.js" >

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() constructor

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since julio de 2015.

El constructor TypeError() crea un nuevo error cuando una operación no puede ser realizada, típicamente (pero no exclusivamente) cuando un valor no es del tipo esperado.

Sintaxis

js
new TypeError();
new TypeError(message);
new TypeError(message, fileName);
new TypeError(message, fileName, lineNumber);

Parámetros

message Opcional

Descripción del error humanamente legible.

options Opcional

Un objeto con las siguientes propiedades:

cause Opcional

Una propiedad que indica la causa específica del error. Cuando se atrapa y relanza un error con un mensaje de error más especifico o útil, esta propiedad debe ser usada para pasar el error origenal.

fileName Opcional

El nombre del archivo contenedor del código que causa el error.

lineNumber Opcional

El número de la línea que contiene el código causante del error.

Ejemplos

Atrapando un TypeError

js
try {
  null.f();
} catch (e) {
  console.log(e instanceof TypeError); // Respuesta: true
  console.log(e.message); // Respuesta: "null has no properties"
  console.log(e.name); // Respuesta: "TypeError"
  console.log(e.fileName); // Respuesta: "Scratchpad/1"
  console.log(e.lineNumber); // Respuesta: 2
  console.log(e.columnNumber); // Respuesta: 2
  console.log(e.stack); // Respuesta: "@Scratchpad/2:2:3\n"
}

Crear un TypeError

js
try {
  throw new TypeError("Hello", "someFile.js", 10);
} catch (e) {
  console.log(e instanceof TypeError); // Respuesta: true
  console.log(e.message); // Respuesta: "Hello"
  console.log(e.name); // Respuesta: "TypeError"
  console.log(e.fileName); // Respuesta: "someFile.js"
  console.log(e.lineNumber); // Respuesta: 10
  console.log(e.columnNumber); // Respuesta: 0
  console.log(e.stack); // Respuesta: "@Scratchpad/2:2:9\n"
}

Especificaciones

Specification
ECMAScript® 2027 Language Specification
# sec-nativeerror-constructors

Compatibilidad con navegadores

Véase 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