JavaScript fromCharCode() | Convert Unicode Values to Characters or String

The JavaScript fromCharCode() method is used when we need to convert Unicode values to its equivalent characters or strings. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="xyz"></p>

   <script>
      let x = String.fromCharCode(65);
      document.getElementById("xyz").innerHTML = x;
   </script>
   
</body>
</html>
Output

That is, the Unicode of A is 65.

JavaScript fromCharCode() Syntax

The syntax of fromCharCode() method in JavaScript is:

String.fromCharCode(Unicode1, Unicode2, Unicode3, ..., UnicodeN)

At least one Unicode value is required as parameter to fromCharCode() method.

The fromCharCode() method returns the equivalent character(s) of Unicode value(s) given as parameters.

Convert Unicode Values to Characters in JavaScript

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="abc"></p>

   <script>
      let myString = String.fromCharCode(99, 111, 100, 101, 115, 99, 114, 97, 99, 107, 101, 114);
      document.getElementById("abc").innerHTML = myString;
   </script>
   
</body>
</html>
Output

JavaScript fromCharCode() Example

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>
   
   <p>The character equivalent to Unicode 65: <span id="a"></span></p>
   <p>The character equivalent to Unicode 66: <span id="b"></span></p>
   <p>The character equivalent to Unicode 89: <span id="c"></span></p>
   <p>The character equivalent to Unicode 90: <span id="d"></span></p>
   <p>The character equivalent to Unicode 97: <span id="e"></span></p>
   <p>The character equivalent to Unicode 98: <span id="f"></span></p>
   <p>The character equivalent to Unicode 121: <span id="g"></span></p>
   <p>The character equivalent to Unicode 122: <span id="h"></span></p>

   <script>
      let m = String.fromCharCode(65);
      let n = String.fromCharCode(66);
      let o = String.fromCharCode(89);
      let p = String.fromCharCode(90);
      let q = String.fromCharCode(97);
      let r = String.fromCharCode(98);
      let s = String.fromCharCode(121);
      let t = String.fromCharCode(122);

      document.getElementById("a").innerHTML = m;
      document.getElementById("b").innerHTML = n;
      document.getElementById("c").innerHTML = o;
      document.getElementById("d").innerHTML = p;
      document.getElementById("e").innerHTML = q;
      document.getElementById("f").innerHTML = r;
      document.getElementById("g").innerHTML = s;
      document.getElementById("h").innerHTML = t;
   </script>
   
</body>
</html>
Output

The character equivalent to Unicode 65:

The character equivalent to Unicode 66:

The character equivalent to Unicode 89:

The character equivalent to Unicode 90:

The character equivalent to Unicode 97:

The character equivalent to Unicode 98:

The character equivalent to Unicode 121:

The character equivalent to Unicode 122:

JavaScript Online Test


« Previous Tutorial Next Tutorial »