9

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 !

3
  • That just means that the font used in your IDE does not support this particular emoji. Commented Sep 4, 2017 at 20:08
  • I tried with DW, SublimeText, PhpSortm, Notepad++ If you know an IDE that supports them, please let me know Commented Sep 4, 2017 at 23:18
  • Just try setting your IDE to a font that you have installed and that can display them. Of course another possibility is that your OS doesn't support copy-pasting them. Commented Sep 5, 2017 at 1:16

2 Answers 2

19
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.

Sign up to request clarification or add additional context in comments.

2 Comments

GREAT: but what about some older browsers ?
There's a polyfill
-1

Use this:

// emoji code from w3schools //
//***************************//
  var code = {
    ok: "9989",     hurrcane : "128165",  Up : "11014",    Down : "11015",    Hashtag : "35",    Clock : "9200", P : "127359",    Okay : "10004",    NotOkay : "10006"
  }
// emoji in javascript       //
//***************************//
  function emoji(ecode)
  {
    return String.fromCodePoint(ecode);
  }
  console.log(emoji(code.Clock)+emoji(code.Okay))

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.