RangeError: argument is not a valid code point
The JavaScript exception "Invalid code point" occurs whenNaN
values,negative Integers (-1), non-Integers (5.4), or values larger than 0x10FFFF (1114111) areused withString.fromCodePoint()
.
Message
RangeError: Invalid code point -1 (V8-based)RangeError: -1 is not a valid code point (Firefox)RangeError: Arguments contain a value that is out of range of code points (Safari)
Error type
What went wrong?
String.fromCodePoint()
throws this error when passedNaN
values, negative Integers (-1), non-Integers (5.4), or values larger than 0x10FFFF(1114111).
Acode point is a value in theUnicode codespace; that is, the range of integers from0
to0x10FFFF
.
Examples
Invalid cases
js
String.fromCodePoint("_"); // RangeErrorString.fromCodePoint(Infinity); // RangeErrorString.fromCodePoint(-1); // RangeErrorString.fromCodePoint(3.14); // RangeErrorString.fromCodePoint(3e-2); // RangeErrorString.fromCodePoint(NaN); // RangeError
Valid cases
js
String.fromCodePoint(42); // "*"String.fromCodePoint(65, 90); // "AZ"String.fromCodePoint(0x404); // 'Є' (U+0404)String.fromCodePoint(0x2f804); // '你' (U+2F804)String.fromCodePoint(194564); // '你'String.fromCodePoint(0x1d306, 0x61, 0x1d307); // '𝌆a𝌇'