首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Errors: Not a codepoint

信息

代码语言:javascript
复制
RangeError: {0} is not a valid code point (Firefox)
RangeError: Invalid code point {0} (Chrome)

错误类型

RangeError

哪里出错了?

String.fromCodePoint()这个方法只能接受有效的码位(code point) 。

码位(?code point)是组成码空间(或代码页)的数值,范围是 0 到 0x10FFFF。

NaN,负整数(-1),非整数(3.14),或编号大于0x10FFFF (1114111) 的字符,无法使用该方法。

示例

无效的情况

代码语言:javascript
复制
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

有效的情况

代码语言:javascript
复制
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"

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com