JavaScript: String.fromCharCode
String.fromCharCode(codeUnit1, codeUnit2 etc)
-
Return a string, where each character in string has corresponding
String Code Unit
.
Each of codeUnit should be a integer from 0 to 65535 inclusive. (Note:
65535 = 2^16 -1
). If it is greater than 65535, a value of modulo(codeUnit, 2^16) is used.// convert sequence of unicode codepoint to string console.log(String.fromCharCode(97, 98) === "ab"); // 97 is the codepoint for letter a // 98 is the codepoint for letter b
// String.fromCharCode won't work as expected if codepoint is greater than 65535 (that's 2^16 ) const xx = String.fromCharCode(128514); const yy = String.fromCharCode(62978); console.log(xx === yy); console.log((xx === "๐") === false); console.log((128514 % (2 ** 16)) === 62978); // ๐ // name: FACE WITH TEARS OF JOY // codepoint decimal: 128514 // codepoint hexadecimal: 1f602