/
index.md
61 lines (45 loc) · 1.63 KB
/
index.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
---
title: "RangeError: argument is not a valid code point"
slug: Web/JavaScript/Reference/Errors/Not_a_valid_code_point
page-type: javascript-error
---
{{jsSidebar("Errors")}}
The JavaScript exception "Invalid code point" occurs when {{jsxref("NaN")}} values,
negative Integers (-1), non-Integers (5.4), or values larger than 0x10FFFF (1114111) are
used with {{jsxref("String.fromCodePoint()")}}.
## Message
```plain
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
{{jsxref("RangeError")}}
## What went wrong?
{{jsxref("String.fromCodePoint()")}} throws this error when passed {{jsxref("NaN")}}
values, negative Integers (-1), non-Integers (5.4), or values larger than 0x10FFFF
(1114111).
A [code point](https://en.wikipedia.org/wiki/Code_point) is a value in the
Unicode codespace; that is, the range of integers from `0` to
`0x10FFFF`.
## Examples
### Invalid cases
```js example-bad
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 example-good
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𝌇'
```
## See also
- {{jsxref("String.fromCodePoint()")}}