JavaScript String fromCharCode() Method

Beginner
⏱️ 10 min read
📚 Updated: Jul 2026
🎯 5 Examples
🚀 5 Try-it labs
Static method

What You’ll Learn

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.

01

Kind

Static method

02

Call as

String.fromCharCode()

03

Returns

String

04

Input range

0–65535

05

Pair with

charCodeAt()

06

Baseline

Widely available

Introduction

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.

💡
Static = call on String

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().

Understanding the fromCharCode() Method

Each argument becomes one UTF-16 code unit in the result string. Pass several numbers to build longer text in one call.

  • Valid units are integers from 0 to 65535 (0xFFFF).
  • Larger numbers are truncated to the lowest 16 bits (no error is thrown).
  • No validity checks — invalid combinations can still produce a string.
  • Supplementary characters need two units (a surrogate pair) or fromCodePoint().

📝 Syntax

General form of the static String.fromCharCode method:

JavaScript
String.fromCharCode()
String.fromCharCode(num1)
String.fromCharCode(num1, num2)
String.fromCharCode(num1, num2, /* …, */ numN)

Parameters

  • num1, …, numN — numbers between 0 and 65535 representing UTF-16 code units. Values above 0xFFFF are truncated to 16 bits.

Return value

A string whose length equals the number of arguments (0 arguments → "").

Common patterns

JavaScript
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)

⚡ Quick Reference

GoalCode
One character from a codeString.fromCharCode(65)"A"
Several charactersString.fromCharCode(65, 66, 67)
Hex code unitString.fromCharCode(0x2014)
Round-tripString.fromCharCode(str.charCodeAt(i))
Full Unicode code pointString.fromCodePoint(0x1f303)
No argumentsString.fromCharCode()""

🔍 At a Glance

Four facts to remember about String.fromCharCode().

Kind
static

Call on String

Input
0–65535

UTF-16 units

Oversize
truncate

Keeps low 16 bits

Emoji tip
fromCodePoint

Easier for U+10000+

📋 fromCharCode() vs fromCodePoint() vs charCodeAt()

fromCharCodefromCodePointcharCodeAt
DirectionNumber(s) → stringCode point(s) → stringString → number
KindStaticStaticInstance
Typical inputUTF-16 unit 0–65535Full Unicode 0–0x10FFFFIndex into a string
Emoji / U+10000+Needs surrogate pairOne code point argMay return half a pair
Best forASCII / BMP unit mathTrue Unicode valuesReading unit numbers

Examples Gallery

Examples follow MDN String.fromCharCode() patterns. Use View Output or Try It Yourself for each case.

📚 Getting Started

Build strings from one or more UTF-16 code units.

Example 1 — Basic fromCharCode()

MDN demo: several code units become one string.

JavaScript
String.fromCharCode(189, 43, 190, 61);
// "½+¾="
Try It Yourself

How It Works

Each number is one UTF-16 unit. Four arguments → a four-character string.

Example 2 — BMP Characters (Letters & Punctuation)

Everyday characters use a single code unit. Hex and decimal both work.

JavaScript
String.fromCharCode(65, 66, 67);  // "ABC"
String.fromCharCode(0x2014);      // "—"
String.fromCharCode(8212);        // "—"  (decimal form of 0x2014)
Try It Yourself

How It Works

6567 are classic ASCII letter codes. 0x2014 / 8212 are the same em dash unit written two ways.

📈 Practical Patterns

Surrogate pairs, round-trips, and truncation surprises.

Example 3 — Surrogate Pair for Emoji

Characters above U+FFFF need two UTF-16 units (MDN Night with Stars).

JavaScript
// 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);        // "🌃"
Try It Yourself

How It Works

One emoji character is stored as two code units. Passing both builds the same string as fromCodePoint(0x1f303) without looking up the pair yourself.

Example 4 — Round-Trip with charCodeAt()

Read codes from text, then rebuild the string.

JavaScript
"A".charCodeAt(0);                         // 65
String.fromCharCode("A".charCodeAt(0));    // "A"

const codes = [..."Hi"].map((c) => c.charCodeAt(0));
String.fromCharCode(...codes);             // "Hi"
Try It Yourself

How It Works

charCodeAt and fromCharCode are inverse for BMP text. Spreading an array of units rebuilds the original string.

Example 5 — Truncation & Empty Call

Oversized numbers keep only the lowest 16 bits. No args → empty string.

JavaScript
String.fromCharCode();                 // ""
String.fromCharCode(0x12014);          // "—"  (same as 0x2014)
String.fromCharCode(65 + 65536);       // "A"  (65 after truncate)
String.fromCharCode(65) === String.fromCharCode(65 + 65536); // true
Try It Yourself

How It Works

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.

🚀 Common Use Cases

  • ASCII / letter math — build alphabets with loops over 6590.
  • Round-trip encoding — store code units, rebuild with fromCharCode.
  • Legacy protocols — APIs that still speak in 16-bit character codes.
  • Teaching UTF-16 — show how emoji need two units.
  • Prefer fromCodePoint for emoji — pass 0x1f303 instead of looking up surrogates.
  • Not for HTML escaping — use proper encode/escape helpers for markup safety.

🧠 How String.fromCharCode() Works

1

Receive code unit numbers

Zero or more numeric arguments (decimal or hex).

Input
2

Truncate to 16 bits

Each value is reduced to a UTF-16 code unit (0–65535).

Mask
3

Append units in order

Arguments become consecutive characters in the result.

Build
4

Return a new string

Length equals the argument count; originals were never needed.

📝 Notes

  • Always call String.fromCharCode(...) — it is static.
  • Pair with charCodeAt() for BMP round-trips.
  • For full Unicode values, prefer String.fromCodePoint().
  • Oversized numbers truncate silently — they do not throw.
  • Surrogate pairs are valid input; lone surrogates produce unpaired units.
  • Related: codePointAt(), String constructor.

Browser & Runtime Support

String.fromCharCode() is Baseline Widely available — supported across browsers for many years.

Baseline · Widely available

String.fromCharCode()

Safe everywhere. Prefer fromCodePoint() when you have a full Unicode code point for emoji.

Universal Widely available
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full support
fromCharCode() Excellent

Bottom line: Use String.fromCharCode() for UTF-16 code units. Remember values above 0xFFFF truncate, and for characters above U+FFFF prefer fromCodePoint().

Conclusion

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.

💡 Best Practices

✅ Do

  • Call String.fromCharCode(...) on the constructor
  • Use it with charCodeAt() for BMP round-trips
  • Prefer fromCodePoint() for emoji / rare characters
  • Pass multiple args to build a string in one call
  • Remember empty call returns ""

❌ Don’t

  • Call fromCharCode on a string instance
  • Assume numbers above 65535 create full Unicode characters
  • Hand-compute surrogates when fromCodePoint is available
  • Expect a RangeError for oversized inputs
  • Confuse code units with user-perceived graphemes

Key Takeaways

Knowledge Unlocked

Five things to remember about String.fromCharCode()

Static builder of strings from UTF-16 code units.

5
Core concepts
🔢 02

Range

0–65535

Units
03

Pair

charCodeAt

Pattern
🌟 04

Emoji

fromCodePoint

Tip
05

Oversize

truncates

Gotcha

❓ Frequently Asked Questions

String.fromCharCode(...nums) is a static method that builds a string from one or more UTF-16 code units (numbers from 0 to 65535). For example String.fromCharCode(65, 66, 67) returns "ABC".
No. It is a static method on the String constructor. Always write String.fromCharCode(...), not "text".fromCharCode(...).
Values above 0xFFFF are truncated to the lowest 16 bits. For example String.fromCharCode(0x12014) behaves like String.fromCharCode(0x2014) and returns an em dash.
Yes, but emoji above U+FFFF need a surrogate pair — two code units. Prefer String.fromCodePoint(0x1f303) when you know the full Unicode code point.
Use charCodeAt() for UTF-16 units or codePointAt() for full Unicode code points. Round-trip: String.fromCharCode("A".charCodeAt(0)) === "A".
An empty string "". Each argument you pass adds one UTF-16 code unit to the result.
Did you know?

String.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.

More String Methods

Return to the hub for slice, trim, replace, and more.

String methods hub →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful