LearnFrenzy
Sign in Take a free test

Strings · Find the Error · Question 15

Bug: the character counter is too high Answer, explanation & discussion

  • Find the error
  • Hard
  • 0 comments
  • Answer explained
  • Moderated community
Question 15 Back to Exercise

The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?

main.js
const status = "Great job \u{1F389}\u{1F389}";   // "Great job 🎉🎉"
console.log(`${status.length}/12 characters`);
  • A Template literals add extra characters
  • B The space is counted twice
  • C length counts UTF-16 units and each emoji uses two – count code points with [...status].length Correct
  • D length includes the quotes
Correct Answer: Option C

"Great job " is 10 units and each 🎉 is 2, so length is 14, although a user sees 12 characters. [...status].length gives 12.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links