Categories
JavaScript Answers

How to Fix the ‘RangeError: radix must be an integer’ Error in Our JavaScript App?

Spread the love

Sometimes, we may run into the ‘RangeError: radix must be an integer’ when we’re developing JavaScript apps.

In this article, we’ll look at how to fix the ‘RangeError: radix must be an integer’ when we’re developing JavaScript apps.

Fix the ‘RangeError: radix must be an integerRangeError: precision is out of range’ When Developing JavaScript Apps

To fix the ‘RangeError: radix must be an integer’ when we’re developing JavaScript apps, we should make sure we pass in an integer between 2 and 36 inclusive as the value of the optional radix parameter of the Number.prototype.toString or BigInt.prototype.toString methods.

In Edge, the same error is called RangeError: invalid argument.

In Firefox, the error is called RangeError: invalid argument.

And in Chrome, the same error is called RangeError: toString() radix argument must be between 2 and 36.

Therefore, instead of writing the following:

(12).toString(0);
(12).toString(1);
(12).toString(37);
(12).toString(150);
(12071989).toString('MM-dd-yyyy')

We write:

(12).toString(2);  
(13).toString(8);  
(0x42).toString(10);
(100000).toString(16)

Conclusion

To fix the ‘RangeError: radix must be an integer’ when we’re developing JavaScript apps, we should make sure we pass in an integer between 2 and 36 inclusive as the value of the optional radix parameter of the Number.prototype.toString or BigInt.prototype.toString methods.

In Edge, the same error is called RangeError: invalid argument.

In Firefox, the error is called RangeError: invalid argument.

And in Chrome, the same error is called RangeError: toString() radix argument must be between 2 and 36.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *