JavaScript String.fromCharCode

fromCharCode() is static method of the String class of the JavaScript. So we can use the fromCharCode() method with String class always. It will create the string from the sequences of the unicode values.



Stirng.fromCharCode() method always returns the string, not any type of object.


document.writeln(String.fromCharCode(74, 97, 118, 97, 83, 99, 114, 105, 112, 116, 32, 72, 105, 118, 101));
//It will print the "JavaScript Hive" on screen.

How to pass an array to String.fromCharCode()

We can also pass the array of the unicode values to the Stirng.fromCharCode() method to generate the string.


array = [72, 69, 76, 76, 79];
document.write(String.fromCharCode.apply(null, array));
//It will print the HELLO on the screen.

Please, take a note that this method may be dangerous, In case of you will try to construct very long string using the String.fromCharCode.apply() method.

The string will have the capital letter or lower letter will be purely depends on the unicode values. If you pass the 65 than it will give the capital A and if you pass the 97 than it will give the small a.
So be careful String.fromCharCode() never take decisions its own about the capital and small letter, It simply works on the unicode values.

 Happy Coding!!!