JavaScript String fromCharCode() Method (original) (raw)

Last Updated : 16 Jul, 2024

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.

**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();

`

**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();

`

**Supported Browsers: