--- title: ReferenceError slug: Web/JavaScript/Referencia/Objetos_globales/ReferenceError tags: - Clase - Class - JavaScript - Object - Objeto - ReferenceError - Referencia translation_of: Web/JavaScript/Reference/Global_Objects/ReferenceError ---
El objeto ReferenceError
representa un error cuando se hace referencia a una variable inexistente.
ReferenceError()
ReferenceError
.message
, en SpiderMonkey
, hereda {{jsxref("Error.prototype.message")}}.ReferenceError
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" }
ReferenceError
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" }
Especificación |
---|
{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard-referenceerror', 'ReferenceError')}} |
{{Compat("javascript.builtins.ReferenceError")}}