In theory, no matter what the input is, the output should be unchanged:
String.fromCharCode("a".charCodeAt(0)); //"a"
This makes sense because I'm just trying to get the char code of a character, and then casting it back to a character.
However when I try with this character, it breaks:
//"": 55356
String.fromCharCode("".charCodeAt(0)); //"�" (65533)
(Note that I actually highlighted the string and pasted it into the next line. It changed to �
by itself for some reason.)
Why is this happening and how can I fix this?
I noticed that there is a new method in ES6, String.fromCodePoint()
but it is not supported every browser except Firefox.