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

df-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

ReferenceError

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.

* Some parts of this feature may have varying levels of support.

El objeto ReferenceError representa un error cuando se hace referencia a una variable inexistente.

Constructor

ReferenceError()

Crea un nuevo objeto ReferenceError.

Propiedades de la instancia

ReferenceError.prototype.message

Mensaje de error. Aunque ECMA-262 especifica que ReferenceError debe proporcionar su propia propiedad message, en SpiderMonkey, hereda Error.prototype.message.

ReferenceError.prototype.name

Nombre del error. Heredado de Error.

ReferenceError.prototype.fileName

Ruta al archivo que generó este error. Heredado de Error.

ReferenceError.prototype.lineNumber

Número de línea en el archivo que generó este error. Heredado de Error.

ReferenceError.prototype.columnNumber

Número de columna en la línea que generó este error. Heredado de Error.

ReferenceError.prototype.stack

Seguimiento de la pila. Heredado de Error.

Ejemplos

Capturar un ReferenceError

js
try {
  let a = undefinedVariable;
} catch (e) {
  console.log(e instanceof ReferenceError); // true
  console.log(e.message); // "undefinedVariable no está definida"
  console.log(e.name); // "ReferenceError"
  console.log(e.fileName); // "Scratchpad/1"
  console.log(e.lineNumber); // 2
  console.log(e.columnNumber); // 6
  console.log(e.stack); // "@Scratchpad/2:2:7\n"
}

Crear un ReferenceError

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

Especificaciones

Specification
ECMAScript® 2027 Language Specification
# sec-native-error-types-used-in-this-standard-referenceerror

Compatibilidad con navegadores

Ve 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