Example 1 — Basic fromCharCode()
MDN demo: several code units become one string.
String.fromCharCode(189, 43, 190, 61);
// "½+¾=" How It Works
Each number is one UTF-16 unit. Four arguments → a four-character string.

String.fromCharCode() is a static helper (same API as MDN String.fromCharCode()). It builds a string from UTF-16 code unit numbers — the reverse of charCodeAt(). Learn multi-argument calls, truncation, surrogate pairs, and when fromCodePoint() is easier — with five examples and try-it labs.
Static method
String.fromCharCode()
String
0–65535
charCodeAt()
Widely available
Most String methods run on text you already have: "Hello".toUpperCase(). fromCharCode() is different — it lives on the String constructor and creates text from numbers.
Those numbers are UTF-16 code units (0–65535), the same values charCodeAt() returns. For characters above U+FFFF (many emoji), you either pass a surrogate pair or use String.fromCodePoint() with the full Unicode value.
Write String.fromCharCode(65). Do not write "A".fromCharCode(65) — that is not how static methods work.
This page is part of JavaScript String Methods under Static Methods. Related topics include charCodeAt() and codePointAt().
fromCharCode() MethodEach argument becomes one UTF-16 code unit in the result string. Pass several numbers to build longer text in one call.
0 to 65535 (0xFFFF).fromCodePoint().General form of the static String.fromCharCode method:
String.fromCharCode()
String.fromCharCode(num1)
String.fromCharCode(num1, num2)
String.fromCharCode(num1, num2, /* …, */ numN) 0 and 65535 representing UTF-16 code units. Values above 0xFFFF are truncated to 16 bits.A string whose length equals the number of arguments (0 arguments → "").
String.fromCharCode(65, 66, 67); // "ABC"
String.fromCharCode(0x2014); // "—"
String.fromCharCode(8212); // "—" (decimal for 0x2014)
String.fromCharCode(0x12014); // "—" (truncated to 0x2014)
// Round-trip with charCodeAt:
String.fromCharCode("A".charCodeAt(0)); // "A"
// Emoji needs a surrogate pair (or use fromCodePoint):
String.fromCharCode(0xd83c, 0xdf03); // "🌃"
String.fromCodePoint(0x1f303); // "🌃" (easier) | Goal | Code |
|---|---|
| One character from a code | String.fromCharCode(65) → "A" |
| Several characters | String.fromCharCode(65, 66, 67) |
| Hex code unit | String.fromCharCode(0x2014) |
| Round-trip | String.fromCharCode(str.charCodeAt(i)) |
| Full Unicode code point | String.fromCodePoint(0x1f303) |
| No arguments | String.fromCharCode() → "" |
Four facts to remember about String.fromCharCode().
staticCall on String
0–65535UTF-16 units
truncateKeeps low 16 bits
fromCodePointEasier for U+10000+
fromCharCode() vs fromCodePoint() vs charCodeAt()fromCharCode | fromCodePoint | charCodeAt | |
|---|---|---|---|
| Direction | Number(s) → string | Code point(s) → string | String → number |
| Kind | Static | Static | Instance |
| Typical input | UTF-16 unit 0–65535 | Full Unicode 0–0x10FFFF | Index into a string |
| Emoji / U+10000+ | Needs surrogate pair | One code point arg | May return half a pair |
| Best for | ASCII / BMP unit math | True Unicode values | Reading unit numbers |
Examples follow MDN String.fromCharCode() patterns. Use View Output or Try It Yourself for each case.
Build strings from one or more UTF-16 code units.
fromCharCode()MDN demo: several code units become one string.
String.fromCharCode(189, 43, 190, 61);
// "½+¾=" Each number is one UTF-16 unit. Four arguments → a four-character string.
Everyday characters use a single code unit. Hex and decimal both work.
String.fromCharCode(65, 66, 67); // "ABC"
String.fromCharCode(0x2014); // "—"
String.fromCharCode(8212); // "—" (decimal form of 0x2014) 65–67 are classic ASCII letter codes. 0x2014 / 8212 are the same em dash unit written two ways.
Surrogate pairs, round-trips, and truncation surprises.
Characters above U+FFFF need two UTF-16 units (MDN Night with Stars).
// Code point U+1F303 "Night with Stars"
String.fromCharCode(0xd83c, 0xdf03); // "🌃"
String.fromCharCode(55356, 57091); // "🌃" (decimal pair)
// Easier with the full code point:
String.fromCodePoint(0x1f303); // "🌃" One emoji character is stored as two code units. Passing both builds the same string as fromCodePoint(0x1f303) without looking up the pair yourself.
charCodeAt()Read codes from text, then rebuild the string.
"A".charCodeAt(0); // 65
String.fromCharCode("A".charCodeAt(0)); // "A"
const codes = [..."Hi"].map((c) => c.charCodeAt(0));
String.fromCharCode(...codes); // "Hi" charCodeAt and fromCharCode are inverse for BMP text. Spreading an array of units rebuilds the original string.
Oversized numbers keep only the lowest 16 bits. No args → empty string.
String.fromCharCode(); // ""
String.fromCharCode(0x12014); // "—" (same as 0x2014)
String.fromCharCode(65 + 65536); // "A" (65 after truncate)
String.fromCharCode(65) === String.fromCharCode(65 + 65536); // true There is no RangeError for large numbers — JavaScript quietly masks to 16 bits. That is why fromCodePoint() is safer when you mean a full Unicode value.
65–90.fromCharCode.0x1f303 instead of looking up surrogates.String.fromCharCode() WorksZero or more numeric arguments (decimal or hex).
Each value is reduced to a UTF-16 code unit (0–65535).
Arguments become consecutive characters in the result.
Length equals the argument count; originals were never needed.
String.fromCharCode(...) — it is static.String.fromCodePoint().String.fromCharCode() is Baseline Widely available — supported across browsers for many years.
Safe everywhere. Prefer fromCodePoint() when you have a full Unicode code point for emoji.
Bottom line: Use String.fromCharCode() for UTF-16 code units. Remember values above 0xFFFF truncate, and for characters above U+FFFF prefer fromCodePoint().
String.fromCharCode() turns UTF-16 code unit numbers into a string — the static partner of charCodeAt(). Use it for BMP text and letter math; reach for fromCodePoint() when you already know the full Unicode value.
Continue with charCodeAt(), codePointAt(), String constructor, or the String methods hub.
String.fromCharCode(...) on the constructorcharCodeAt() for BMP round-tripsfromCodePoint() for emoji / rare characters""fromCharCode on a string instance65535 create full Unicode charactersfromCodePoint is availableString.fromCharCode()Static builder of strings from UTF-16 code units.
String.fromCharCode
API0–65535
UnitscharCodeAt
PatternfromCodePoint
Tiptruncates
GotchaString.fromCodePoint() was added later so you can pass values like 0x1f303 directly. Under the hood it still stores emoji as UTF-16 surrogate pairs — the same units fromCharCode accepts.
Return to the hub for slice, trim, replace, and more.
8 people found this page helpful