JavaScript String.fromCharCode() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.fromCharCode(...nums) is a static method that builds a string from one or more UTF-16 code units (numbers 0–65535). Call it on String, not on a string value.

Pass the required arguments shown below. Check return values and browser support before you rely on the result.

Syntax

Call String.fromCharCode. Start with this line.

JavaScript
String.fromCharCode(n1, n2, …)
CallWhat it does
String.fromCharCode(n1, n2, …)Primary signature.
String.fromCharCode(...)Call with the arguments your case needs.

Built into JavaScript. Call String.fromCharCode(...) on the String constructor — no import required.

Library declarations
JavaScript
String.fromCharCode(n1, n2, …)

Parameters

ParameterDescription
Code unit numbersOptional. Each arg → one UTF-16 unit; none → ""

Return Value

Return ValueDescription
*The value returned by String.fromCharCode().

JavaScript Examples

Example 1 — Build a String from Code Units

Pass one or more UTF-16 numbers to get characters back.

JavaScript
console.log(String.fromCharCode(65, 66, 67));
// "ABC"

console.log(String.fromCharCode(72, 101, 108, 108, 111));
// "Hello"

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

How It Works

  1. Call the static method. Use String.fromCharCode, not a string instance.
  2. Map each number. 65→"A", 66→"B", 67→"C".
  3. Join in order. Arguments become characters left to right.
  4. Beyond ASCII. Values like 189 still work — they are valid UTF-16 units.

Example 2 — Round-Trip with charCodeAt()

Convert characters to numbers and back with the matching pair of APIs.

JavaScript
const letter = "A";
const code = letter.charCodeAt(0);           // 65

console.log(code);
console.log(String.fromCharCode(code));      // "A"
console.log(String.fromCharCode(0x12014));   // "—" (truncated)
console.log(String.fromCharCode(0x2014));    // "—"
Try It Yourself

How It Works

  1. Read a unit. charCodeAt(0) returns the UTF-16 code for "A" → 65.
  2. Rebuild the char. fromCharCode(65) returns "A" again.
  3. Watch truncation. 0x12014 keeps only the lowest 16 bits → same as 0x2014.
  4. Pair them mentally. Numbers ↔ characters for BMP text use this duo.

Example 3 — fromCharCode vs fromCodePoint

Emoji need a surrogate pair with fromCharCode, or one call to fromCodePoint.

JavaScript
// Night with stars (U+1F303) — two UTF-16 units:
console.log(String.fromCharCode(0xd83c, 0xdf03));

// Same emoji with one Unicode code point:
console.log(String.fromCodePoint(0x1f303));

console.log(
  String.fromCharCode(0xd83c, 0xdf03) ===
  String.fromCodePoint(0x1f303)
); // true
Try It Yourself

How It Works

  1. UTF-16 split. Code points above U+FFFF need two units (a surrogate pair).
  2. Manual pair. fromCharCode(0xd83c, 0xdf03) builds the emoji from those units.
  3. Easier API. fromCodePoint(0x1f303) takes the full Unicode scalar value.
  4. Rule of thumb. Prefer fromCodePoint for emoji and astral characters.

Browser & Runtime Support

String.fromCharCode() is a long-standing part of JavaScript. It works in all modern browsers and Node.js versions you are likely to target.

✓ Baseline · Widely available

String.fromCharCode()

Supported everywhere Unicode strings are — including legacy browsers. No polyfill needed for normal web or Node targets.

100% Universal support
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: Safe to use in any environment that runs JavaScript. For astral Unicode (emoji), prefer String.fromCodePoint when available (ES2015+).

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.

Next: fromCodePoint()

Build strings from full Unicode code points — better for emoji and astral characters.

fromCodePoint() tutorial →

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.

11 people found this page helpful