Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

String.fromCharCode — build text from UTF-16 code units

String.fromCharCode creates a string from supplied UTF-16 code units. It does not interpret arguments as complete Unicode code points: characters outside the Basic Multilingual Plane require a surrogate pair.

Version: ECMAScript and Web APIs; exact feature edition and browser support reviewed per entry; Node 24 in repository does not prove browser API support

Syntax

String.fromCharCode(...codeUnits)

String.fromCharCode(...codeUnits) is a static method of the String constructor, not a method on an individual string. It returns a new string containing UTF-16 code units in argument order. With no arguments, it returns "". It belongs to ECMAScript, not a browser API.

Each argument undergoes ToUint16: conversion to a number, truncation toward zero, and reduction modulo 65536. NaN, Infinity, and -Infinity produce a code unit with value 0. Out-of-range values do not themselves cause a RangeError; for example, 0x10041 produces the same code unit as 65. Converting a Symbol or BigInt causes a TypeError.

A code unit does not always represent a complete Unicode character. For code point 0x1F600, supply the surrogate pair 0xD83D, 0xDE00; the result has a length of 2. If your inputs are code points, use String.fromCodePoint. String.fromCharCode does not validate surrogate pairing and can create a lone surrogate.

The example demonstrates letters, a surrogate pair, modulo reduction, and a call without arguments. Do not treat this method as a UTF-8 byte decoder.

Examples

const text = String.fromCharCode(65, 66, 67);
const emoji = String.fromCharCode(0xD83D, 0xDE00);
console.log(text);
console.log(emoji === String.fromCodePoint(0x1F600));
console.log(emoji.length);
console.log(String.fromCharCode(0x10041) === "A");
console.log(String.fromCharCode() === "");

Result

ABC
true
2
true
true

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources