JavaScript | String.fromCharCode()
String.fromCharCode() function is used to create a string from the given sequence of UTF-16 code units. The syntax of this function is as follows:
String.fromCharCode(n1, n2, ..., nX)
Arguments
The function takes the UTF-16 Unicode sequences as its argument. The number of arguments to this function 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 function is a string containing the characters whose UTF-16 codes were passed to the function as arguments.
Examples for the above function are provided below:
Example 1:
print(String.fromCharCode(65, 66, 67));
Output:
ABC
In this example the function 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 function 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 function are provided below:
Program 1:
<script> // JavaScript to illustrate fromCharCode() function function 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() function function func() { // UTF-16 code to be converted into character var str = String.fromCharCode(0x12014); document.write(str); } func(); </script> |
Output:
—
Recommended Posts:
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Operators in JavaScript
- JavaScript Course | Functions in JavaScript
- JavaScript Course | Objects in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Variables in JavaScript
- JavaScript Course | JavaScript Prompt Example
- JavaScript vs Python : Can Python Overtop JavaScript by 2020?
- How to include a JavaScript file in another JavaScript file ?
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


