--- title: RangeError slug: Web/JavaScript/Reference/Global_Objects/RangeError tags: - Error - JavaScript - NeedsTranslation - Object - RangeError - TopicStub translation_of: Web/JavaScript/Reference/Global_Objects/RangeError ---
The RangeError
object indicates an error when a value is not in the set or range of allowed values.
new RangeError([message[, fileName[, lineNumber]]])
message
fileName
{{non-standard_inline}}lineNumber
{{non-standard_inline}}A RangeError
is thrown when trying to pass a number as an argument to a function that does not allow a range that includes that number. This can be encountered when attempting to create an array of an illegal length with the {{jsxref("Array")}} constructor, or when passing bad values to the numeric methods {{jsxref("Number.toExponential()")}}, {{jsxref("Number.toFixed()")}} or {{jsxref("Number.toPrecision()")}}.
RangeError
object.The global RangeError
contains no methods of its own, however, it does inherit some methods through the prototype chain.
RangeError
instancesRangeError
var check = function(num) { if (num < MIN || num > MAX) { throw new RangeError('Parameter must be between ' + MIN + ' and ' + MAX); } }; try { check(500); } catch (e) { if (e instanceof RangeError) { // Handle range error } }
Specification | Status | Comment |
---|---|---|
{{SpecName('ES3')}} | {{Spec2('ES3')}} | Initial definition. |
{{SpecName('ES5.1', '#sec-15.11.6.2', 'RangeError')}} | {{Spec2('ES5.1')}} | |
{{SpecName('ES6', '#sec-native-error-types-used-in-this-standard-rangeerror', 'RangeError')}} | {{Spec2('ES6')}} | |
{{SpecName('ESDraft', '#sec-native-error-types-used-in-this-standard-rangeerror', 'RangeError')}} | {{Spec2('ESDraft')}} |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} | {{CompatVersionUnknown}} |