Saturday, September 6, 2025
HomeLanguagesJavascriptJavaScript RangeError Argument is not a valid code point

JavaScript RangeError Argument is not a valid code point

This JavaScript exception Invalid code point occurs if NaN values, negative Integers, non-Integers, or other values larger than 0x10FFFF are used with the String.fromCodePoint() method.

Output:

RangeError: {0} is not a valid code point (Firefox)
RangeError: Invalid code point {0} (Chromium)

Error Type:

RangeError

Cause of the error: The String.fromCodePoint() is used to return a string created using the sequence of code points that are specified as parameters. It throws this error if the passed code point values are NaN values, negative Integers, non-Integers, or values larger than 0x10FFFF.

Example 1: This example works without throwing any error because the value passed to the method is valid.

Javascript




function Geeks() {
    try {
        String.fromCodePoint(34);
 
        console.log("'Argument is not a valid code point'" +
            " error has not occurred");
    } catch (e) {
 
        // Show the error in console
        console.log(e);
 
        console.log("'Argument is not a valid code point'" +
            " error has occurred");
    }
}
 
Geeks();


Output:

'Argument is not a valid code point' error has not occurred

Example 2: In this example, the value passed to the method is NaN, which is an invalid value, therefore the error has occurred.

Javascript




function Geeks() {
    try {
        String.fromCodePoint(NaN);
 
        console.log("'Argument is not a valid code point'" +
            " error has not occurred");
    } catch (e) {
 
        // Show the error in console
        console.log(e);
         
        console.log("'Argument is not a valid code point'" +
            " error has occurred");
    }
}
 
Geeks();


Output:

'Argument is not a valid code point' error has occurred
RELATED ARTICLES

Most Popular

Dominic
32269 POSTS0 COMMENTS
Milvus
82 POSTS0 COMMENTS
Nango Kala
6639 POSTS0 COMMENTS
Nicole Veronica
11803 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11868 POSTS0 COMMENTS
Shaida Kate Naidoo
6752 POSTS0 COMMENTS
Ted Musemwa
7029 POSTS0 COMMENTS
Thapelo Manthata
6704 POSTS0 COMMENTS
Umr Jansen
6721 POSTS0 COMMENTS