Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

JavaScript String fromCharCode() Method

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

The JavaScript String.fromCharCode() method is used to create a string from the given sequence of UTF-16 code units. This method returns a string, not a string object.

Syntax:

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

Parameters: 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.

Below is an example of the String.fromCharCode() Method.

Example: 

JavaScript




function func() {
    let str = String.fromCharCode(71, 70, 71);
    console.log(str);
}
func();


Output:

GFG

Examples of the above method are provided below: 

Example 1: 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. 

JavaScript




// JavaScript to illustrate fromCharCode() method
function func() {
 
    // UTF-16 codes to be converted into characters
    let str = String.fromCharCode(65, 66, 67);
    console.log(str);
}
 
func();


Output:

ABC

Example 2: 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 —.

JavaScript




// JavaScript to illustrate fromCharCode() method
function func() {
 
    // UTF-16 code to be converted into character
    let str = String.fromCharCode(0x12014);
    console.log(str);
}
 
func();


Output:

We have a complete list of Javascript string methods, to check those please go through this Javascript String Complete reference article.

Supported Browsers: 

  • Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera 4 and above
  • Safari 1 and above

My Personal Notes arrow_drop_up
Last Updated : 22 May, 2023
Like Article
Save Article
Similar Reads
Related Tutorials