范围错误:参数不是有效的代码点

NaN 值、负整数 (-1)、非整数 (5.4) 或大于 0x10FFFF (1114111) 的值与 String.fromCodePoint() 一起使用时,会发生 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: 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

RangeError

什么地方出了错?

¥What went wrong?

当传递 NaN 值、负整数 (-1)、非整数 (5.4) 或大于 0x10FFFF (1114111) 的值时,String.fromCodePoint() 会引发此错误。

¥String.fromCodePoint() throws this error when passed NaN values, negative Integers (-1), non-Integers (5.4), or values larger than 0x10FFFF (1114111).

代码点 是 Unicode 代码空间中的一个值;即从 00x10FFFF 的整数范围。

¥A code point is a value in the Unicode codespace; that is, the range of integers from 0 to 0x10FFFF.

示例

¥Examples

无效案例

¥Invalid cases

js
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

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𝌇'

也可以看看