JavaScript String.fromCodePoint() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Method

Definition

String.fromCodePoint(...nums) is a static method (ES2015) that builds a string from one or more Unicode code points (0–0x10FFFF). One argument can make an emoji — no surrogate-pair math required.

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

Syntax

Call String.fromCodePoint. Start with this line.

JavaScript
String.fromCodePoint(cp1, cp2, …)
CallWhat it does
String.fromCodePoint(cp1, cp2, …)Primary signature.
String.fromCodePoint(...)Call with the arguments your case needs.

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

Library declarations
JavaScript
String.fromCodePoint(cp1, cp2, …)

Parameters

ParameterDescription
Code point numbersOptional. Each arg → one Unicode character; none → ""
Valid rangeRequired. Integer 0–0x10FFFF, or RangeError

Return Value

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

JavaScript Examples

Example 1 — Code Points to Characters

Build ASCII text and emoji from full Unicode values.

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

console.log(String.fromCodePoint(0x1f303));
// "🌃"

console.log(String.fromCodePoint(0x1f600, 0x1f64f));
// "😀🙏"
Try It Yourself

How It Works

  1. Call the static method. Use String.fromCodePoint, not a string instance.
  2. ASCII still works. 65, 66, 67 become "ABC".
  3. One emoji, one number. 0x1f303 is enough — no surrogate pair needed.
  4. Multiple args join. Each code point is appended in order.

Example 2 — Round-Trip with codePointAt()

Read a code point from a string and rebuild the same character.

JavaScript
const emoji = "🌃";
const cp = emoji.codePointAt(0);   // 127747

console.log(cp);
console.log(cp.toString(16));      // "1f303"
console.log(String.fromCodePoint(cp));
console.log(emoji.length);         // 2 (UTF-16 units)
Try It Yourself

How It Works

  1. Read the scalar. codePointAt(0) returns the full Unicode value, not just the first unit.
  2. Hex helps reading. toString(16) shows the familiar 1f303 form.
  3. Rebuild. fromCodePoint(cp) returns the same emoji.
  4. Remember length. Astral characters often have length === 2 in JavaScript strings.

Example 3 — fromCodePoint vs fromCharCode

Compare one clear code point with a surrogate pair, and see a RangeError.

JavaScript
console.log(String.fromCodePoint(0x1f303));
console.log(String.fromCharCode(0xd83c, 0xdf03));

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

try {
  String.fromCodePoint(0x110000); // too large
} catch (e) {
  console.log(e.name); // RangeError
}
Try It Yourself

How It Works

  1. Prefer clarity. One fromCodePoint arg beats two surrogate units.
  2. Same result. Both paths can build the same emoji string.
  3. Strict range. Values above 0x10FFFF throw — they are not truncated.
  4. Rule of thumb. Use fromCodePoint for Unicode scalars; fromCharCode for raw UTF-16 units.

Browser & Runtime Support

String.fromCodePoint() is part of ES2015 (ES6). It works in all modern browsers and Node.js versions in common use today.

✓ Baseline · ES2015

String.fromCodePoint()

Supported in Chrome 41+, Firefox 29+, Safari 9+, Edge 12+, and Node.js 4+. Not available in Internet Explorer without a polyfill.

98% Modern browser 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
fromCodePoint() Excellent

Bottom line: Safe for modern web apps and current Node LTS. For very old targets, feature-detect with typeof String.fromCodePoint === "function" or fall back to fromCharCode with surrogate pairs.

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)) === "🌃".

Next: String.raw()

Learn how to get raw template-string text without escape processing.

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