JavaScript String.fromCharCode()

String.fromCharCode() creates a string from one or more UTF-16 code-unit numbers. It is called on the String constructor, not on an existing string value.

console.log(String.fromCharCode(70)); // F

String.fromCharCode() Syntax Top ↑

String.fromCharCode(num1, num2)

You can supply one or more numbers. The method returns a new string made from those UTF-16 code units.

Create Several Characters at Once Top ↑

This preserves the original multi-value example.

console.log(String.fromCharCode(70, 71, 72)); // FGH

ASCII-Range Examples Top ↑

console.log(String.fromCharCode(65)); // A
console.log(String.fromCharCode(97)); // a
console.log(String.fromCharCode(48)); // 0

Values 0–127 correspond to the ASCII range, but the JavaScript method itself works with UTF-16 code units.

Generate a Character Table with a Loop Top ↑

The original page generated code tables with document.write(). A modern version can build rows in memory and place them into the DOM.

const rows = [];
for (let i = 32; i <= 126; i++) {
  rows.push(`${i} = ${String.fromCharCode(i)}`);
}
console.log(rows.join("\n"));

The table-generation example also uses a JavaScript for loop.

See the interactive fromCharCode character table for a browser output.

Reverse Conversion with charCodeAt() Top ↑

const letter = "P";
const unit = letter.charCodeAt(0);
console.log(unit);                    // 80
console.log(String.fromCharCode(unit)); // P

See charCodeAt() for the full reverse-direction discussion.

fromCharCode() vs fromCodePoint() Top ↑

Use String.fromCodePoint() when you have complete Unicode code-point values, especially values above 0xFFFF.

console.log(String.fromCodePoint(0x1F600)); // 😀

What Happens to Values Above 65535? Top ↑

fromCharCode() converts each argument to a 16-bit code unit, so higher bits are discarded. That is another reason fromCodePoint() is clearer for full Unicode code points.

Common String.fromCharCode() Mistakes Top ↑

  • Calling it as an instance method such as text.fromCharCode().
  • Describing all returned values as ASCII characters.
  • Using it for a code point above 0xFFFF instead of String.fromCodePoint().
  • Building large DOM outputs with repeated document.write().

String Reference Lowercase Strings




Subscribe to our YouTube Channel here



plus2net.com










We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
©2000-2026   plus2net.com   All rights reserved worldwide Privacy Policy Disclaimer