Question 15
Back to Exercise
The code below runs without an error, but its result is wrong. Which statement correctly identifies the bug?
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!