JavaScript String fromCodePoint() Method

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

What You’ll Learn

String.fromCodePoint() is a static helper (same API as MDN String.fromCodePoint()). It builds a string from full Unicode code points β€” including emoji β€” without manually writing surrogate pairs. Learn valid ranges, RangeError rules, how length can grow, and how it compares to fromCharCode() β€” with five examples and try-it labs.

01

Kind

Static method

02

Call as

String.fromCodePoint()

03

Returns

String

04

Input range

0–0x10FFFF

05

Invalid

RangeError

06

Baseline

Widely available

Introduction

Unicode code points run from 0 to 0x10FFFF (over one million values). Everyday letters sit in the BMP (below 65536). Many emoji and rare characters sit higher and need two UTF-16 code units in memory.

fromCodePoint() lets you pass the real Unicode value β€” for example 0x1f303 for 🌃 β€” and JavaScript builds the correct UTF-16 storage for you. That is easier than looking up a surrogate pair for fromCharCode().

💡
Static = call on String

Write String.fromCodePoint(0x1f303). Do not write "πŸŒƒ".fromCodePoint(...) β€” static methods live on the constructor.

This page is part of JavaScript String Methods under Static Methods. Related topics include fromCharCode() and codePointAt().

Understanding the fromCodePoint() Method

Each argument is one Unicode code point. The method returns a string made of those characters in order. Unlike fromCharCode, invalid numbers throw instead of silently truncating.

  • Valid integers: 00x10FFFF (inclusive).
  • Non-integers, negatives, NaN, Infinity, or values above the max → RangeError.
  • Supplementary characters may make result.length larger than the argument count.
  • Pair with codePointAt() to round-trip full Unicode values.

📝 Syntax

General form of the static String.fromCodePoint method:

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

Parameters

  • num1, …, numN — integers between 0 and 0x10FFFF (inclusive) representing Unicode code points.

Return value

A string created from the given code points. No arguments → "".

Exceptions

RangeError if any value is not a valid integer code point after conversion.

Common patterns

JavaScript
String.fromCodePoint(65, 90);       // "AZ"
String.fromCodePoint(0x1f303);      // "πŸŒƒ"
String.fromCodePoint(0x2f804);      // "π― „"

// Round-trip with codePointAt:
String.fromCodePoint("πŸŒƒ".codePointAt(0)); // "πŸŒƒ"

// fromCharCode needs a surrogate pair for the same emoji:
String.fromCharCode(0xd83c, 0xdf03); // "πŸŒƒ"

⚡ Quick Reference

GoalCode
One character from a code pointString.fromCodePoint(0x1f303)
Several charactersString.fromCodePoint(65, 90)
Round-tripString.fromCodePoint(str.codePointAt(i))
UTF-16 units onlyString.fromCharCode(...)
Invalid inputRangeError
No argumentsString.fromCodePoint()""

🔍 At a Glance

Four facts to remember about String.fromCodePoint().

Kind
static

Call on String

Input
0–0x10FFFF

Full code points

Invalid
RangeError

No silent truncate

Emoji
one arg

No surrogate lookup

📋 fromCodePoint() vs fromCharCode() vs codePointAt()

fromCodePointfromCharCodecodePointAt
DirectionCode point(s) → stringUTF-16 unit(s) → stringString → code point
KindStaticStaticInstance
Typical input0–0x10FFFF0–65535Index into a string
Emoji / U+10000+One argumentNeeds surrogate pairReturns full value
Bad numbersRangeErrorTruncate (no throw)N/A
Best forTrue Unicode valuesBMP / unit mathReading code points

Examples Gallery

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

📚 Getting Started

Build strings from one or more Unicode code points.

Example 1 — Basic fromCodePoint()

MDN demo: mix of symbols and a supplementary character.

JavaScript
String.fromCodePoint(9731, 9733, 9842, 0x2f804);
// "β˜ƒβ˜…β™²π― „"
Try It Yourself

How It Works

Four code points become one string. The last value (0x2f804) is above the BMP, so it is stored as a UTF-16 surrogate pair internally.

Example 2 — Valid BMP Inputs

Everyday characters use a single code unit when below 0x10000.

JavaScript
String.fromCodePoint(42);        // "*"
String.fromCodePoint(65, 90);    // "AZ"
String.fromCodePoint(0x404);     // "Π„"
Try It Yourself

How It Works

Hex and decimal both work. Multiple arguments concatenate characters in order.

📈 Practical Patterns

Emoji, length surprises, and invalid-input errors.

Example 3 — Emoji Without Surrogate Pairs

MDN comparison: one code point vs two UTF-16 units.

JavaScript
String.fromCodePoint(0x1f303);           // "πŸŒƒ"
String.fromCodePoint(127747);            // "πŸŒƒ"  (decimal)

// Same character via fromCharCode (surrogate pair):
String.fromCharCode(0xd83c, 0xdf03);     // "πŸŒƒ"
Try It Yourself

How It Works

Prefer fromCodePoint when you know the Unicode value. Use fromCharCode only when you already have the two UTF-16 units.

Example 4 — Mixed Code Points & length

One argument can still produce length === 2 for supplementary characters.

JavaScript
const s = String.fromCodePoint(0x1d306, 0x61, 0x1d307);
// "πŒ†aπŒ‡"

s.length;                 // 5  (two pairs + "a")
[...s].length;            // 3  (three code points)
"πŸŒƒ".length;               // 2
String.fromCodePoint(0x1f303).length; // 2
Try It Yourself

How It Works

length counts UTF-16 units. Spread / iteration walk by code point β€” that is why [...s].length matches the argument count here.

Example 5 — Invalid Inputs Throw RangeError

Unlike fromCharCode, bad values are rejected (MDN Invalid input).

JavaScript
// String.fromCodePoint("_");      // RangeError
// String.fromCodePoint(Infinity); // RangeError
// String.fromCodePoint(-1);       // RangeError
// String.fromCodePoint(3.14);     // RangeError

String.fromCodePoint();            // ""
Try It Yourself

How It Works

Wrap calls in try/catch when values come from user input. An empty call is valid and returns an empty string.

🚀 Common Use Cases

  • Emoji / rare characters — pass the Unicode value directly (no surrogate math).
  • Round-trip with codePointAt — store and rebuild full characters safely.
  • Unicode tables / generators — loop code points in a known range.
  • Safer than fromCharCode for U+10000+ — throws on invalid values instead of truncating.
  • Teaching UTF-16 — show why length can be 2 for one visible character.
  • Not for grapheme clusters — skin tones / ZWJ sequences are multiple code points.

🧠 How String.fromCodePoint() Works

1

Receive code point numbers

Zero or more numeric arguments (decimal or hex).

Input
2

Validate each value

Must be an integer in 00x10FFFF or throw RangeError.

Check
3

Encode to UTF-16

BMP → one unit; supplementary → surrogate pair.

Encode
4

Return a new string

Characters appear in argument order; length may exceed arg count.

📝 Notes

  • Always call String.fromCodePoint(...) β€” it is static.
  • Prefer it over fromCharCode() for values above 0xFFFF.
  • Pair with codePointAt() for round-trips.
  • Invalid numbers throw RangeError β€” they do not truncate.
  • length counts UTF-16 units, not necessarily β€œvisible characters.”
  • Related: charCodeAt(), [Symbol.iterator]().

Browser & Runtime Support

String.fromCodePoint() is Baseline Widely available β€” supported across modern browsers since ES2015.

Baseline · Widely available

String.fromCodePoint()

Safe for production. Prefer fromCodePoint() for full Unicode values; use fromCharCode() when you already have UTF-16 units.

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
fromCodePoint() Excellent

Bottom line: Use String.fromCodePoint() for Unicode code points 0–0x10FFFF. Invalid values throw RangeError. One emoji argument may still produce length 2.

Conclusion

String.fromCodePoint() turns full Unicode code points into a string β€” the static partner of codePointAt(). Use it for emoji and rare characters without surrogate-pair math; use fromCharCode() when you already work in UTF-16 units.

Continue with fromCharCode(), codePointAt(), String constructor, or the String methods hub.

💡 Best Practices

✅ Do

  • Call String.fromCodePoint(...) on the constructor
  • Use it for emoji / values above 0xFFFF
  • Pair with codePointAt() for round-trips
  • Catch RangeError when inputs are untrusted
  • Remember length may be 2 for one emoji

❌ Don’t

  • Call fromCodePoint on a string instance
  • Pass fractions, NaN, or negatives and expect truncation
  • Assume argument count always equals result.length
  • Hand-build surrogate pairs when you know the code point
  • Confuse code points with grapheme clusters (skin tones, ZWJ)

Key Takeaways

Knowledge Unlocked

Five things to remember about String.fromCodePoint()

Static builder of strings from full Unicode code points.

5
Core concepts
🔢 02

Range

0–0x10FFFF

Unicode
🌟 03

Emoji

one argument

Win
⚠️ 04

Invalid

RangeError

Safety
📏 05

length

may be 2

UTF-16

❓ Frequently Asked Questions

String.fromCodePoint(...nums) is a static method that builds a string from one or more Unicode code points (integers from 0 to 0x10FFFF). For example String.fromCodePoint(0x1f303) returns the emoji πŸŒƒ.
No. It is a static method on the String constructor. Always write String.fromCodePoint(...), not "text".fromCodePoint(...).
fromCharCode() takes UTF-16 code units (0–65535) and truncates larger values. fromCodePoint() takes full Unicode code points and can create emoji in one argument. Invalid fromCodePoint inputs throw RangeError instead of truncating.
length counts UTF-16 code units. Code points above U+FFFF are stored as a surrogate pair, so one fromCodePoint argument can produce length 2.
When a value is not an integer, is less than 0, is greater than 0x10FFFF, or is NaN/Infinity after conversion β€” for example String.fromCodePoint(-1) or String.fromCodePoint(3.14).
Use codePointAt(index). Round-trip: String.fromCodePoint("πŸŒƒ".codePointAt(0)) === "πŸŒƒ".
Did you know?

fromCodePoint and codePointAt were added in ES2015 together so JavaScript could round-trip characters beyond the BMP without forcing every developer to memorize surrogate-pair formulas.

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