RangeError: Invalid code point
Error message
Invalid code point U+XXXX
Quick summary
You called String.fromCodePoint() with a value that is not a valid Unicode code point — it must be a non-negative integer up to 0x10FFFF.
Why this happens
Passed a negative number to String.fromCodePoint()
Passed a number greater than 0x10FFFF (the max Unicode code point)
Passed a non-integer or NaN
Minimal example
const char = String.fromCodePoint(-1);const code = Math.max(0, Math.min(0x10FFFF, Math.floor(-1)));
const char = String.fromCodePoint(code);Negative code points are invalid. Clamp the value to the valid range [0, 0x10FFFF].
How to diagnose
Log the value being passed to String.fromCodePoint()
Check that it is a non-negative integer within the valid Unicode range
Validate the input before using it
How to fix
Validate the code point is between 0 and 0x10FFFF
Use Math.floor() to ensure an integer
Provide a fallback for invalid code points
How to prevent
Validate Unicode code points before passing them to String.fromCodePoint()
Related Resources
Related Lessons
- Data Types
Learn about strings and Unicode.