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(num1, num2)
You can supply one or more numbers. The method returns a new string made from those UTF-16 code units.
This preserves the original multi-value example.
console.log(String.fromCharCode(70, 71, 72)); // FGH
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.
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.
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.
Use String.fromCodePoint() when you have complete Unicode code-point values, especially values above 0xFFFF.
console.log(String.fromCodePoint(0x1F600)); // 😀
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.
text.fromCharCode().0xFFFF instead of String.fromCodePoint().document.write().String Reference Lowercase Strings
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.