JavaScript fromCharCode() method explained

A short guide on how JavaScript fromCharCode() method works

Posted on May 17, 2021

The JavaScript fromCharCode() method is a static method of the JavaScript String object that allows you to convert a Unicode number.

A Unicode number is a unique number representing a character that’s acknowledged as the global identifier for that character in the world of information technology.

The Unicode number provides a consistent and compatible representation of each character in many technological systems.

For example, the Unicode number 65 equals A the uppercase letter, while Unicode number 97 equals a the lowercase letter.

For the full list of Unicode number, refer to Wikipedia here

You can use the method by calling it directly from the String object instead of the object’s instance.

The fromCharCode() syntax is as follows:

String.fromCharCode(unicodeNum, unicodeNum, ...);

You are free to pass one or more Unicode numbers as you need. The method will return an empty string "" if you don’t pass any valid Unicode numbers.

Here’s an example of the method in action:

String.fromCharCode(65); // "A"
String.fromCharCode(65, 66, 67); // "ABC"
String.fromCharCode(72, 69, 89); // "HEY"
String.fromCharCode(); // ""

The return value of the method will be a string that you can use further in your JavaScript application.

Related articles:

Grab the free JavaScript book today 👍

Learn the building blocks of JavaScript programming language like data types, functions, objects, arrays and classes.

Use the knowledge from the book to build a small but solid program.

Learn more