JS: 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
JavaScript. String, Char, Encoding, Hexadecimal
JS String.prototype
- JS: String.prototype.constructor
- JS: String.prototype.length
- JS: String.prototype.at
- JS: String.fromCharCode
- JS: String.prototype.concat
- JS: String.prototype.repeat
- JS: String.prototype.trim
- JS: String.prototype.trimStart
- JS: String.prototype.trimEnd
- JS: String.prototype.padStart
- JS: String.prototype.padEnd
- JS: String.prototype.slice
- JS: String.prototype.substring
- JS: String.prototype.substr
- JS: String.prototype.indexOf
- JS: String.prototype.lastIndexOf
- JS: String.prototype.includes
- JS: String.prototype.startsWith
- JS: String.prototype.endsWith
- JS: String.prototype.search
- JS: String.prototype.match
- JS: String.prototype.matchAll
- JS: String.prototype.replace
- JS: String.prototype.split
- JS: String.prototype.toLowerCase
- JS: String.prototype.charAt
- JS: String.prototype.charCodeAt
- JS: String.prototype.codePointAt