javascript - How to correctly use Unicode and UTF-8 special characters in Node and browser js? -


so have character:

๐Ÿ€€

mahjong tile east wind has unicode point u+1f000 (u+d83c u+dc00) , utf-8 encoding f0 9f 80 80

my question how escape in javascript?

i see \uff00 time, ascii 8 bytes take 255. putting \u1f000' returns (incorrect) 'แผ€0' , trying fill in bytes 0s returns \u0001f000'. how escape values higher (such above character?).

and how escape not unicode point utf-8 encoding?

taking on this, have noticed node repl able show many unicode values not (such emoji) when terminal window (mac) could. there rhyme or reason this

you can escape char using \uxxxx x2 (for 32-bit values) format.

to use utf-8 strings typed arrays , textencoder / textdecoder. new may need use polyfill in browsers.

example

document.write('<h1>\ud83c\udc00</h1>');


Comments