KIRUPA 🍊
KIRUPA 🍊
HomeArchiveLeaderboardAbout
Sign in

Which came first! The πŸ” or the πŸ₯š?

Let’s definitively answer this age old question by using Array.sort() and learn why the outcome is what it is.

KIRUPA 🍊's avatar
KIRUPA 🍊
Nov 14

Hi everybody - Daniel Stolbov recently answered the age old question of whether the chicken came first or the egg came first using JavaScript. In my latest video, I dive further into it and explain why the outcome is what it is:

The full code for answering this question is as follows:

let egg = "πŸ₯š";
let chicken = "πŸ”";

let arrayToSort = [egg, chicken];

let sortedArray = arrayToSort.sort();

console.log(`The ${sortedArray[0]} came first!`);

When this code runs, the console output will say that the…πŸ₯β€¦chicken came first! The reason for this has to do with how emojis are represented.

Say Hello to Codepoints

The critical detail here is something known as codepoints. Codepoints are unique numerical values that identify specific characters in Unicode, including emojis. Think of them as the ID numbers for each character or emoji. For example, the "thumbs up" emoji πŸ‘ has the codepoint U+1F44D.

Similarly, our egg and chicken emojis have codepoint values as well:

let eggCodepoint = "πŸ₯š".codePointAt(0).toString(16);
let chickenCodepoint = "πŸ”".codePointAt(0).toString(16);

console.log(`Egg's codepoint: ${eggCodepoint}`); // 1F95A
console.log(`Chicken's codepoint: ${chickenCodepoint}`); // 1F414

The codepoint for the egg emoji is 1F95A, and the codepoint for the chicken emoji is 1F414.

When we call array.sort() on our array of emojis, our emojis are sorted by their codepoint values. Because the chicken emoji has a smaller codepoint than the egg emoji, the chicken emoji comes first. It is just a simple number sorting thing. There is no deeper meaning or insight sadly being implied here! 😎

Till Next Time

I hope you found this quick JavaScript sorting tip, disguised as a fun exercise, helpful and entertaining.

As always, I like to hear from you. To discuss this further, feel free to continue the conversation on my Twitter / X post on this or on the forums.

Cheers,
Kirupa πŸ˜€

Discussion about this post

User's avatar
Nicolas's avatar
Nicolas
Nov 14, 2024

Chicken or the egg?

The first amniotic eggs preceded Chickens by at least

340 Millions of years

Like (1)
Reply
Share
1 reply by KIRUPA 🍊
1 more comment...

Keep reading

KIRUPA 🍊

Thought provoking and educational content that lives at the intersection of design 🎨, development πŸ€–, and business πŸ’°.

  • About
  • Archive
  • Recommendations
  • Sitemap
Β© 2026 KIRUPA 🍊 Β· Privacy βˆ™ Terms βˆ™ Collection notice
Start your SubstackGet the app
Substack is the home for writing, podcasting, and media founders.