HTML: Markup language
CSS: Styling language
JavaScript: Scripting language
Web APIs: Programming interfaces
All web technology
Learn web development
Discover our tools
Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
View in English Always switch to English
This feature is well established and works across many devices and browser versions. It’s been available across browsers since июль 2015 г..
* Some parts of this feature may have varying levels of support.
Объект ReferenceError представляет ошибку, возникающую при обращении к переменной, которая не существует (или не была инициализирована) в текущей области видимости.
ReferenceError
ReferenceError является сериализуемым объектом, поэтому он может быть клонирован с помощью structuredClone() или передан между воркерами с использованием postMessage().
structuredClone()
postMessage()
RangeReferenceErrorError является подклассом Error.
RangeReferenceErrorError
Error
ReferenceError()
Создаёт новый объект ReferenceError.
Также наследует свойства экземпляра своего родителя Error.
Эти свойства определены в ReferenceError.prototype и есть у всех экземпляров ReferenceError.
ReferenceError.prototype
ReferenceError.prototype.constructor
Функция-конструктор, создающая экземпляр объекта. Для экземпляров ReferenceError начальным значением является конструктор ReferenceError.
ReferenceError.prototype.name
Представляет название типа ошибки. Начальным значением ReferenceError.prototype.name является "ReferenceError".
"ReferenceError"
Наследует методы экземпляра своего родителя Error.
try { let a = undefinedVariable; } catch (e) { console.log(e instanceof ReferenceError); // true console.log(e.message); // "undefinedVariable is not defined" console.log(e.name); // "ReferenceError" console.log(e.stack); // Стек ошибок }
try { throw new ReferenceError("Привет"); } catch (e) { console.log(e instanceof ReferenceError); // true console.log(e.message); // "Привет" console.log(e.name); // "ReferenceError" console.log(e.stack); // Стек ошибок }
Enable JavaScript to view this browser compatibility table.