The `fromCharCode` method in JavaScript returns a string created by using the specified sequence of Unicode values.
The syntax of String.fromCharCode() static-method is:
String.fromCharCode()
String.fromCharCode(num1)
String.fromCharCode(num1, num2)
String.fromCharCode(num1, num2, /* …, */ numN)
This fromCharCode() static-method of String returns a string created by using the specified sequence of Unicode values.
Parameter | Optional/Required | Description |
---|---|---|
num1, num2, ... , numN | required | A sequence of Unicode values representing characters to include in the string. |
String.fromCharCode() returns value of type String
.
In this example,
fromCharCode()
method with the Unicode value 65.void main() {
let numCode = String.fromCharCode(65);
console.log('Character for Unicode 65:', numCode);
}
Character for Unicode 65: A
In this example,
fromCharCode()
method with Unicode values 65, 66, and 67.void main() {
let charCodes = String.fromCharCode(65, 66, 67);
console.log('Characters for Unicode 65, 66, 67:', charCodes);
}
Characters for Unicode 65, 66, 67: ABC
In this example,
fromCharCode()
method with a mix of Unicode values.void main() {
let mixedCodes = String.fromCharCode(65, 66, 67, 97, 98, 99);
console.log('Mixed Characters:', mixedCodes);
}
Mixed Characters: ABCabc
In this JavaScript tutorial, we learned about fromCharCode() static-method of String: the syntax and few working examples with output and detailed explanation for each example.