Open In App

JavaScript String fromCharCode() Method

Improve
Improve
Like Article
Like
Save
Share
Report

The fromCharCode() method in JavaScript is a static method of the String object. Which is used to create a string from a sequence of Unicode values.

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.

JavaScript String fromCharCode() Method Examples

Example 1: Using JavaScript’s String.fromCharCode() Method to Generate a String

The function func() uses String.fromCharCode() to convert Unicode values (71, 70, 71) into characters (‘G’, ‘F’, ‘G’), generating the string “GFG” which is then logged to the console.

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

Output
GFG

Example 2: Converting Unicode Point to Character with JavaScript’s fromCharCode()

The function func() utilizes String.fromCharCode() to translate the UTF-16 code point 0x12014 into its respective character. Subsequently, the character is printed to the console, showcasing the conversion process.

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: 


Last Updated : 14 Mar, 2024
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads