String.fromCharCode
Creates a string from character codes.
Available since: ES1
Syntax
String.fromCharCode(code1, code2, /* … */)Parameters
| Parameter | Type | Description |
|---|---|---|
| code1, … | number | UTF-16 character codes. |
Return value
stringA string made of those characters.
Examples
Letters from their codes:
console.log(String.fromCharCode(72, 105));Output:
HiAn alphabet from a range of codes:
const letters = Array.from({ length: 5 }, (_, i) => String.fromCharCode(65 + i));
console.log(letters.join(''));Output:
ABCDENotes
It is a static method: you call it on String itself, not on a string.
See also
- String.prototype.charCodeAt — Returns the numeric code of a character.
- String.prototype.at — Returns the character at a position; negative indexes are allowed.
In the tutorial
- String methods — Useful string methods in JavaScript: finding a position, reading characters, padStart, repeat, split and join, method chains.