The Wayback Machine - https://web.archive.org/web/20240629012247/https://www.geeksforgeeks.org/javascript-string-fromcharcode-method/
Open In App

JavaScript String fromCharCode() Method

Last Updated : 14 Mar, 2024
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: 


Previous Article
Next Article

Similar Reads

TypeScript String.fromCharCode() Method
The fromCharCode() is an inbuilt TypeScript String method. It mainly changes Unicode code points within the Basic Multilingual Plane (BMP) into strings. Although it provides a method for dealing with characters through typing on a keyboard it has restrictions when it comes to characters, outside the BMP. Syntax:String.fromCharCode(...codePoints: nu
1 min read
Difference between String.slice and String.substring in JavaScript
These 2 functions are quite similar in their Syntax But are different in some cases. Let's see the difference between them. JavaScript slice() Method:This method selects the part of a string and returns the selected part as a new string. Start and end parameters are used to specify the extracted part. The first character starts with index 0. Syntax
3 min read
Javascript Program to Check if a string can be formed from another string by at most X circular clockwise shifts
Given an integer X and two strings S1 and S2, the task is to check that string S1 can be converted to the string S2 by shifting characters circular clockwise atmost X times. Input: S1 = "abcd", S2 = "dddd", X = 3 Output: Yes Explanation: Given string S1 can be converted to string S2 as- Character "a" - Shift 3 times - "d" Character "b" - Shift 2 ti
3 min read
Javascript Program to Check if a string can be obtained by rotating another string d places
Given two strings str1 and str2 and an integer d, the task is to check whether str2 can be obtained by rotating str1 by d places (either to the left or to the right). Examples: Input: str1 = "abcdefg", str2 = "cdefgab", d = 2 Output: Yes Rotate str1 2 places to the left. Input: str1 = "abcdefg", str2 = "cdfdawb", d = 6 Output: No Approach: An appro
4 min read
Javascript Program to Check if a string can be obtained by rotating another string 2 places
Given two strings, the task is to find if a string can be obtained by rotating another string two places. Examples: Input: string1 = "amazon", string2 = "azonam" Output: Yes // rotated anti-clockwiseInput: string1 = "amazon", string2 = "onamaz" Output: Yes // rotated clockwise Asked in: Amazon Interview Recommended: Please solve it on “PRACTICE ” f
2 min read
Check if a Given String is Binary String or Not in JavaScript
Binary strings are sequences of characters containing only the digits 0 and 1. Other than that no number can be considered as Binary Number. We are going to check whether the given string is Binary or not by checking it's every character present in the string. Example: Input: "101010"Output: True, binary stringInput: "110211"Output: Falee,Explanati
3 min read
JavaScript Program to Return Original String of Compressed String
The compressed string follows a format where each character is followed by its count. we need to print a string having the same number of characters present in the compressed string. Below are the approaches to return original string of compressed string using Example: Input: compressedString= "a3b2c1"Output: originalString="aaabbc"These are the fo
2 min read
Smallest Window in a String Containing all the Characters of Another String using JavaScript
Given two strings, "str" (the larger string) and "pattern" (the smaller string), the task is to find the smallest window in "str" that contains all the characters of "pattern" in any order using JavaScript. Examples: Input: str = "ADOBECODEBANC"pattern = "ABC"Output: BANCInput: str = "this is a test string"pattern = "tist";Output: t striTable of Co
3 min read
How to count string occurrence in string using JavaScript ?
In JavaScript, we can count the string occurrence in a string by counting the number of times the string is present in the string. This can be done in the following ways: Table of Content Approach 1: Using match() functionApproach 2: Using a loopApproach 3: Using split() functionApproach 4: Using Indexof()Approach 5: Using regular expressionsApproa
4 min read
Check if a string is a valid JSON string using JavaScript
We will be given a string and we need to validate whether the given string is a valid JSON string or not. JSON string is the same as a javaScript object and it must follow the syntax of that object. If the syntax is correct then we have to return true or we have to return false. Methods to Check if a String is Valid JSON String: Table of Content Us
5 min read
three90RightbarBannerImg