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
Fundamentals
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.
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: 0 … 0x10FFFF (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.
Foundation
📝 Syntax
General form of the static String.fromCodePoint method:
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.
UniversalWidely available
Google ChromeSupported · Desktop & Mobile
Full support
Mozilla FirefoxSupported · Desktop & Mobile
Full support
Apple SafariSupported · macOS & iOS
Full support
Microsoft EdgeSupported · Chromium
Full support
Internet ExplorerNo native support · Use a polyfill
Polyfill
OperaSupported · Modern versions
Full support
Samsung InternetSupported · Android
Full support
BunSupported · JavaScript runtime
Supported
DenoSupported · JavaScript runtime
Supported
Node.jsSupported · Server runtime
Supported
Android WebViewSupported · 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.
Wrap Up
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.
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)
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about String.fromCodePoint()
Static builder of strings from full Unicode code points.
5
Core concepts
📄01
Static
String.fromCodePoint
API
🔢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.