JavaScript fromCharCode() method explained

Posted on May 17, 2021

A short guide on how JavaScript fromCharCode() method works

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.

Level up your programming skills

I'm sending out an occasional email with the latest programming tutorials. Drop your email in the box below and I'll send new stuff straight into your inbox!

No spam. Unsubscribe anytime.