/

HTML / CSS / JavaScript Tutorial

JavaScript String method: fromCharCode()

[this page | pdf | back links]

The fromCharCode() method (when applied to the JavaScript String object) converts Unicode values into characters.

 

It has the following syntax with the following parameters:

 

String.fromCharCode(n1, n2, …)

 

Parameter

Required / Optional

Description

n1, n2, …

Required

One or more Unicode values to be converted into a string

 

EXAMPLE:


HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>

<script>
var y = "abcde", y2 = "cde";
document.getElementById("Example").innerHTML =
  'var x = String.fromCharCode(66,67);';
document.getElementById("Result").innerHTML =
  String.fromCharCode(66,67);
</script>

</body>
</html>

FUNCTION THAT MAY ASSIST IN TESTING WHETHER FEATURE IS SUPPORTED:
function isSupportedJavaScriptMethodStringFromCharCode() {
  var z = "abc"; return !!z.fromCharCode;
}


NAVIGATION LINKS
Contents | Prev | Next | JavaScript String Variables


Desktop view | Switch to Mobile