JavaScript String fromCharCode() Method
Below is the example of the String.fromCharCode() Method.
Hey geek! The constant emerging technologies in the world of web development always keeps the excitement for this subject through the roof. But before you tackle the big projects, we suggest you start by learning the basics. Kickstart your web development journey by learning JS concepts with our JavaScript Course. Now at it's lowest price ever!
- Example:
<script>functionfunc() {varstr = String.fromCharCode(71, 70, 71);document.write(str);}func();</script> - Output:
GFG
String.fromCharCode() method is used to create a string from the given sequence of UTF-16 code units.
Syntax:
String.fromCharCode(n1, n2, ..., nX)
Arguments:
The method takes the UTF-16 Unicode sequences as its argument. The number of arguments to this method depends upon the number of characters to be joined as a string. The range of the numbers is between 0 and 65535
Return value:
The return value of this method is a string containing the characters whose UTF-16 codes were passed to the method as arguments.
Examples for the above method are provided below:
Example 1:
print(String.fromCharCode(65, 66, 67));
Output:
ABC
In this example the method fromCharCode() converts the UTF-16 codes into their equivalent characters and returns the string containing them as the answer. In this case the answer is ABC.
Example 2:
String.fromCharCode(0x12014);
Output:
—
In this example the method fromCharCode() converts the UTF-16 code into its equivalent character and returns the string containing it as the answer. In this case the answer is —.
Codes for the above method are provided below:
Program 1:
<script>// JavaScript to illustrate fromCharCode() methodfunction func() { // UTF-16 codes to be converted into characters var str = String.fromCharCode(65, 66, 67); document.write(str);} func();</script> |
Output:
ABC
Program 2:
<script>// JavaScript to illustrate fromCharCode() methodfunction func() { // UTF-16 code to be converted into character var str = String.fromCharCode(0x12014); document.write(str); } func();</script> |
Output:
—
Supported Browsers:
- Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Internet Explorer 4 and above
- Opera 4 and above
- Safari 1 and above


