RangeError: argument is not a valid code point - JavaScript 编辑
The JavaScript exception "Invalid code point" occurs when NaN
values, negative Integers (-1), non-Integers (5.4), or values larger than 0x10FFFF (1114111) are used with String.fromCodePoint()
.
Message
RangeError: {0} is not a valid code point (Firefox) RangeError: Invalid code point {0} (Chromium)
Error type
What went wrong?
String.fromCodePoint()
throws this error when passed NaN
values, negative Integers (-1), non-Integers (5.4), or values larger than 0x10FFFF (1114111).
A code point is a value in the Unicode codespace; that is, the range of integers from 0
to 0x10FFFF
.
Examples
Invalid cases
String.fromCodePoint('_'); // RangeError
String.fromCodePoint(Infinity); // RangeError
String.fromCodePoint(-1); // RangeError
String.fromCodePoint(3.14); // RangeError
String.fromCodePoint(3e-2); // RangeError
String.fromCodePoint(NaN); // RangeError
Valid cases
String.fromCodePoint(42); // "*"
String.fromCodePoint(65, 90); // "AZ"
String.fromCodePoint(0x404); // "\u0404"
String.fromCodePoint(0x2F804); // "\uD87E\uDC04"
String.fromCodePoint(194564); // "\uD87E\uDC04"
String.fromCodePoint(0x1D306, 0x61, 0x1D307) // "\uD834\uDF06a\uD834\uDF07"
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论