Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJulieta Dalla Pozza
4,337 PointsEMOJIS
Can somebody could explain me how is possible to use emojis in code?
1 Answer
Jason Larson
8,361 PointsThere are a couple of different ways to do it. An emoji is basically just text, so you can just copy and paste an emoji from somewhere like Emojipedia. You can also use the CodePoint value. Depending on where you're trying to use it, the prefix is different. Since the question is marked as JavaScript, I'll answer that. You would use the String.fromCodePoint() method, replacing the U+ with 0x. For example, to use the hamburger emoji (which has a CodePoint of U+1F354), you could write something like
console.log(String.fromCodePoint(0x1F354));
Remember that if you are just copying it and pasting it, surround it with quotes so it is treated like a string.
console.log("🍔");
There is a good article about this here.