What is String.fromCharCode() in JS?
Overview
The fromCharCode method is defined in the String class in JS and converts the given sequence of numbers to a string.
Syntax
String.fromCharCode(...);
Parameters
...is a sequence of numbers (e.g.,num1, num2, ..., numN) that specifies the UTF-16 encoding for the string.
Return value
- A string of equivalent length to the number of arguments is returned. The string is constructed by treating the arguments as UTF-16 encoding units.
Example
console.log(String.fromCharCode(0x41, 0x42, 0x43));console.log(String.fromCharCode(97, 98, 99));
In the example above, the first call to fromCharCode passed 3 arguments in hexadecimal notation that represent A, B, and C characters in UTF-16 encoding. The second call to fromCharCode passed 3 arguments as integers that represent a, b, and c characters in UTF-16 encoding.
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved