Javascript Reference - JavaScript String fromCharCode() Method








fromCharCode() takes one or more character codes and convert them into a string.

This is a static method of the String object.

Browser Support

fromCharCode() Yes Yes Yes Yes Yes

Syntax

String.fromCharCode(n1, n2, ..., nX);

Parameter Values

Parameter Description
n1, n2, ..., nX Required. One or more Unicode values to convert




Return Value

A string converted from unicode number(s).

Example


<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {<!--  w w w . j  ava 2  s .co m-->
    var res = String.fromCharCode(66);
    document.getElementById("demo").innerHTML = res;
}
</script>
</body>
</html>

The code above is rendered as follows:





Example 2


console.log(String.fromCharCode(104, 101, 108, 108, 111)); 

The code above generates the following result.