Skip to content

Commit 35997a4

Browse files
From char code new entry (#7046)
* Create fromCharCode.md * Fix formatting in fromCharCode documentation syntax section * Fix code block language in fromCharCode documentation * minor content fixes ---------
1 parent 6779331 commit 35997a4

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
Title: 'fromCharCode()'
3+
Description: 'Returns a string created from the specified sequence of UTF-16 code units.'
4+
Subjects:
5+
- 'Computer Science'
6+
- 'Web Development'
7+
Tags:
8+
- 'Characters'
9+
- 'JavaScript'
10+
- 'Methods'
11+
- 'Strings'
12+
CatalogContent:
13+
- 'introduction-to-javascript'
14+
- 'paths/front-end-engineer-career-path'
15+
---
16+
17+
In JavaScript, the **`fromCharCode()`** method creates a string by converting one or more UTF-16 code units (numeric values) into their corresponding characters. This method is often applied in scenarios involving character encoding, dynamic character generation, or simple encryption tasks. It is particularly useful for converting ASCII or Unicode values into readable text.
18+
19+
## Syntax
20+
21+
```pseudo
22+
String.fromCharCode(num1, num2, ..., numN)
23+
```
24+
25+
**Parameters:**
26+
27+
- `num1, num2, ..., numN` (Number): One or more integer values representing UTF-16 code units. Each number should be between 0 and 65535.
28+
29+
**Return value:**
30+
31+
Returns a string composed of characters corresponding to the provided UTF-16 code units.
32+
33+
## Example
34+
35+
The following code converts a sequence of UTF-16 code units into the string "Liany❤️" and logs it to the console:
36+
37+
```js
38+
const number = String.fromCharCode(76, 105, 97, 110, 121, 10084, 65039);
39+
console.log(number);
40+
```
41+
42+
The output of this code is:
43+
44+
```shell
45+
Liany❤️
46+
```
47+
48+
## Codebyte Example
49+
50+
Run the following code to understand the working of the `fromCharCode()` method:
51+
52+
```codebyte/javascript
53+
const secret = String.fromCharCode(
54+
76, 111, 110, 103, 32, 108, 105, 118, 101, 32, 116, 104, 101, 32, 107, 105, 116, 116, 105, 101, 115
55+
);
56+
console.log(secret);
57+
```

0 commit comments

Comments
 (0)