Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to insert emoticons chars into JS script

How can I use emoticon chars in JS :

http://unicode.org/emoji/charts/full-emoji-list.html#1f600

I tried with:

var emoji = String.fromCharCode(0x1F621);
var emoji = '\u1F600';

I also tried to copy/paste them into phpStorm IDE and into sublime text : that gave me a squared missing char.

I just need to have a console.log('😡') inside my JS !

like image 360
yarek Avatar asked Sep 04 '17 19:09

yarek


1 Answers

var emoji = String.fromCodePoint(0x1F621)

Result:

"😡"

Be careful about limited browser support, though, as String.fromCodePoint() is part of the ES2015 standard. See Mozilla's polyfill if needed.

The language spec explains why fromCharCode does not work:

[the argument is] converted to a character by applying the operation ToUint16 and regarding the resulting 16-bit integer as the code unit value of a character.

and the emoji block is beyond the maximum value supported by unsigned 16-bit integers.

like image 185
Hugues M. Avatar answered Sep 27 '22 19:09

Hugues M.