Categories
JavaScript Answers

How to Fix the ‘RangeError: argument is not a valid code point ‘ Error in Our JavaScript App?

Spread the love

Sometimes, we may run into the ‘RangeError: argument is not a valid code point’ when we’re developing JavaScript apps.

In this article, we’ll look at how to fix the ‘RangeError: argument is not a valid code point’ when we’re developing JavaScript apps.

Fix the ‘RangeError: argument is not a valid code point’ When Developing JavaScript Apps

To fix the ‘RangeError: argument is not a valid code point’ when we’re developing JavaScript apps, we should make sure that we call the String.fromCodePoint method with a valid code point value.

For instance, the following will throw this error:

String.fromCodePoint('_');      
String.fromCodePoint(Infinity); 
String.fromCodePoint(-1);       
String.fromCodePoint(3.14);     
String.fromCodePoint(3e-2);     
String.fromCodePoint(NaN);

These values aren’t numbers that represent characters in the Unicode character set, so the calls above will all throw errors.

On the other hand, the following won’t throw the error since the arguments are all valid Unicode code point values:

String.fromCodePoint(42);     
String.fromCodePoint(65, 90); 
String.fromCodePoint(0x404);  
String.fromCodePoint(0x2F804);
String.fromCodePoint(194564);
String.fromCodePoint(0x1D306, 0x61, 0x1D307)

Conclusion

To fix the ‘RangeError: argument is not a valid code point’ when we’re developing JavaScript apps, we should make sure that we call the String.fromCodePoint method with a valid code point value.

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 *