Skip to content
Tutorials Center
My learning

Topics

JavaScript Reference ยท String

String.fromCodePoint()

Reference for JavaScript String.fromCodePoint(): create a string from Unicode code points, including emoji, and how it differs from String.fromCharCode().

String.fromCodePoint() builds a string from one or more Unicode code points. Unlike String.fromCharCode(), it understands the full Unicode range up to U+10FFFF, so it can produce emoji and rare characters in a single argument. Characters above U+FFFF are stored by JavaScript as a pair of UTF-16 code units, and this method creates that pair for you.

It is the inverse of codePointAt(). Where the number is out of range or not a whole number, it throws instead of silently wrapping.

JavaScript
String.fromCodePoint(0x1f600); // "๐Ÿ˜€"

Try it

JS Code points to text

Press Run (or Ctrl + Enter) to see the console output here.

No output.

JS Invalid input throws

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Syntax

JavaScript
String.fromCodePoint()
String.fromCodePoint(num1)
String.fromCodePoint(num1, num2, /* โ€ฆ, */ numN)
Name Description
num1, โ€ฆ, numN Integer code points from 0 to 0x10FFFF (1,114,111). Numeric strings are converted.

Return value: a string made of the given code points, in order. With no arguments it returns an empty string.

Exceptions: RangeError if an argument is not an integer, is negative, is greater than 0x10FFFF, or is NaN or infinite.

Usage notes

  • Static method. Call it on String: String.fromCodePoint(...).
  • Length counts code units. A code point above 0xFFFF produces a string of length 2 (a surrogate pair). Use the spread operator or for...of to count or iterate by code point.
  • Stricter than fromCharCode(). That method wraps modulo 65536 and truncates fractions; fromCodePoint() throws a RangeError, which exposes bugs earlier.
  • Surrogate code points are accepted. String.fromCodePoint(0xd800) returns a lone surrogate without error. Such strings are not well formed; test with isWellFormed() before sending them where valid Unicode is required.
  • A code point is not a visible character. What users see as one character (a grapheme) can combine several code points, such as a letter plus an accent or an emoji with a skin-tone modifier. Use Intl.Segmenter to work with graphemes.
  • Hexadecimal literals are convenient: write 0x1f680, or parseInt("1F680", 16) when the number comes from text.
  • Escapes for fixed text. In source code, "\u{1f680}" is clearer than a call when the character is a constant.
  • Spread limit. Spreading a very large array into the call can hit the engine's argument limit; convert in chunks.

Browser support

String.fromCodePoint() arrived with ES2015 and works in all current browsers and Node.js. It is missing in very old browsers such as Internet Explorer.